Skip to content

Commit

Permalink
networkConnections: improved parsing (macOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Dec 13, 2024
1 parent e91f61d commit e8732d4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -1534,20 +1534,19 @@ function networkConnections(callback) {
});
}
if (_darwin) {
let cmd = 'netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6\\|Recv-Q"';
let cmd = 'netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6"';
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) {
exec('ps -axo pid,command', { maxBuffer: 1024 * 20000 }, function (err2, stdout2) {
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(' ');
const hasTransferred = line.length >= 19;
if (line.length >= 8) {
let localip = line[3];
let localport = '';
Expand Down

0 comments on commit e8732d4

Please sign in to comment.