networkConnections: improved parsing (macOS)
This commit is contained in:
parent
81d816769c
commit
e91f61dd17
@ -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],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user