fix networkConnections()

This commit is contained in:
Sebastian Hildebrandt
2024-12-23 09:39:58 +01:00
parent 8a801aec95
commit 7eb83e2565
6 changed files with 13 additions and 15 deletions
+4 -10
View File
@@ -1535,7 +1535,7 @@ function networkConnections(callback) {
});
}
if (_darwin) {
let cmd = 'netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6"';
let cmd = 'netstat -natvln | head -n2; 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'.split('|');
exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
if (!error) {
@@ -1543,15 +1543,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');
let pidPos = 8;
if (lines[0] !== '') {
const lineParts = lines[0].replace(/ +/g, ' ').split(' ');
for (let i = 0; i < lineParts.length; i++) {
if (states.indexOf(lineParts[i]) >= 0) {
pidPos = i + 3;
}
};
}
lines.shift();
const header = lines.shift().replace(/ Address/g, '_Address').replace(/ +/g, ' ').split(' ');
let pidPos = header.indexOf('pid');
lines.forEach(function (line) {
line = line.replace(/ +/g, ' ').split(' ');
if (line.length >= 8) {
+1 -1
View File
@@ -176,7 +176,7 @@ function ifaceListLinux() {
}
function nmiDeviceLinux(iface) {
const cmd = `nmcli -t -f general,wifi-properties,capabilities,ip4,ip6 device show ${iface} 2>/dev/null`;
const cmd = `nmcli -t -f general,wifi-properties,capabilities,ip4,ip6 device show ${iface} 2> /dev/null`;
try {
const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
const ssid = util.getValue(lines, 'GENERAL.CONNECTION');