networkConnections() refactored PID parsing (macOS)

This commit is contained in:
Sebastian Hildebrandt
2024-12-21 17:47:49 +01:00
parent 93ccfdf3db
commit 1dd534d4cd
4 changed files with 13 additions and 6 deletions
+6 -5
View File
@@ -1417,9 +1417,10 @@ function getProcessName(processes, pid) {
}
});
cmd = cmd.split(' -')[0];
// return cmd;
const cmdParts = cmd.split('/');
return cmdParts[cmdParts.length - 1];
cmd = cmd.split(' /')[0];
return cmd;
// const cmdParts = cmd.split('/');
// return cmdParts[cmdParts.length - 1];
}
function networkConnections(callback) {
@@ -1546,7 +1547,7 @@ function networkConnections(callback) {
lines.forEach(function (line) {
line = line.replace(/ +/g, ' ').split(' ');
const hasTransferred = line.length >= 19;
const hasTransferred = line.length >= 17;
if (line.length >= 8) {
let localip = line[3];
let localport = '';
@@ -1566,7 +1567,7 @@ function networkConnections(callback) {
}
const hasState = states.indexOf(line[5]) >= 0;
let connstate = hasState ? line[5] : 'UNKNOWN';
let pid = parseInt(line[8 + (hasState ? 0 : -1) + (hasTransferred ? 2 : 0)], 10);
let pid = parseInt(line[6 + (hasState ? 0 : -1) + (hasTransferred ? 2 : 0)], 10);
if (connstate) {
result.push({
protocol: line[0],