networkConnections() fix pid issue (macOS)

This commit is contained in:
Sebastian Hildebrandt
2025-12-08 20:07:25 +01:00
parent c6e8ae960a
commit 647d778c5f
52 changed files with 1547 additions and 1511 deletions
+12 -2
View File
@@ -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],