diff --git a/lib/network.js b/lib/network.js index 160bd34..d33cf81 100644 --- a/lib/network.js +++ b/lib/network.js @@ -1534,8 +1534,7 @@ function networkConnections(callback) { }); } if (_darwin) { - // let cmd = 'netstat -natv | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN"'; - let cmd = 'netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6"'; + let cmd = 'netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6\\|Recv-Q"'; const states = 'ESTABLISHED|SYN_SENT|SYN_RECV|FIN_WAIT1|FIN_WAIT_1|FIN_WAIT2|FIN_WAIT_2|TIME_WAIT|CLOSE|CLOSE_WAIT|LAST_ACK|LISTEN|CLOSING|UNKNOWN'; exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) { if (!error) { @@ -1543,6 +1542,9 @@ function networkConnections(callback) { let processes = stdout2.toString().split('\n'); processes = processes.map((line => { return line.trim().replace(/ +/g, ' '); })); let lines = stdout.toString().split('\n'); + const header = lines[0]; + const hasTransferred = header.indexOf('rxbytes') > -1; + lines.shift(); lines.forEach(function (line) { line = line.replace(/ +/g, ' ').split(' '); @@ -1565,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)], 10); + let pid = parseInt(line[8 + (hasState ? 0 : -1) + (hasTransferred ? 2 : 0)], 10); if (connstate) { result.push({ protocol: line[0],