networkConnections() fix pid issue (macOS)
This commit is contained in:
+12
-2
@@ -1563,7 +1563,7 @@ function networkConnections(callback) {
|
||||
lines.shift();
|
||||
let pidPos = 8;
|
||||
if (lines.length > 1 && lines[0].indexOf('pid') > 0) {
|
||||
const header = (lines.shift() || '').replace(/ Address/g, '_Address').replace(/ +/g, ' ').split(' ');
|
||||
const header = (lines.shift() || '').replace(/ Address/g, '_Address').replace(/process:/g, "").replace(/ +/g, ' ').split(' ');
|
||||
pidPos = header.indexOf('pid');
|
||||
}
|
||||
lines.forEach(function (line) {
|
||||
@@ -1587,7 +1587,17 @@ function networkConnections(callback) {
|
||||
}
|
||||
const hasState = states.indexOf(line[5]) >= 0;
|
||||
let connstate = hasState ? line[5] : 'UNKNOWN';
|
||||
let pid = parseInt(line[pidPos + (hasState ? 0 : -1)], 10);
|
||||
let pidField = "";
|
||||
if (line[line.length - 9].indexOf(":") >= 0) {
|
||||
pidField = line[line.length - 9].split(":")[1];
|
||||
} else {
|
||||
pidField = line[pidPos + (hasState ? 0 : -1)];
|
||||
|
||||
if (pidField.indexOf(":") >= 0) {
|
||||
pidField = pidField.split(":")[1];
|
||||
}
|
||||
}
|
||||
let pid = parseInt(pidField, 10);
|
||||
if (connstate) {
|
||||
result.push({
|
||||
protocol: line[0],
|
||||
|
||||
Reference in New Issue
Block a user