networkConnection() UPD support (mac OS)

This commit is contained in:
Sebastian Hildebrandt 2022-11-15 22:44:57 +01:00
parent 978029ceb9
commit 62d98d6844

View File

@ -328,7 +328,6 @@ function getWindowsIfaceDNSsuffix(ifaces, ifacename) {
if (!dnsSuffix) { dnsSuffix = ''; } if (!dnsSuffix) { dnsSuffix = ''; }
return dnsSuffix; return dnsSuffix;
} catch (error) { } catch (error) {
// console.log('Error getting Connection-specific DNS suffix: ', error.message);
return 'Unknown'; return 'Unknown';
} }
} }
@ -501,7 +500,6 @@ function parseLinesDarwinNics(sections) {
function getDarwinNics() { function getDarwinNics() {
const cmd = '/sbin/ifconfig -v'; const cmd = '/sbin/ifconfig -v';
try { try {
// console.log('SYNC - Nics darwin 12');
const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n'); const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n');
const nsections = splitSectionsNics(lines); const nsections = splitSectionsNics(lines);
return (parseLinesDarwinNics(nsections)); return (parseLinesDarwinNics(nsections));
@ -620,7 +618,6 @@ function getDarwinIfaceDHCPstatus(iface) {
let result = false; let result = false;
const cmd = `ipconfig getpacket "${iface}" 2>/dev/null | grep lease_time;`; const cmd = `ipconfig getpacket "${iface}" 2>/dev/null | grep lease_time;`;
try { try {
// console.log('SYNC - DHCP status darwin 17');
const lines = execSync(cmd).toString().split('\n'); const lines = execSync(cmd).toString().split('\n');
if (lines.length && lines[0].startsWith('lease_time')) { if (lines.length && lines[0].startsWith('lease_time')) {
result = true; result = true;
@ -1484,7 +1481,9 @@ function networkConnections(callback) {
}); });
} }
if (_darwin) { 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 -natv | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN"';
let cmd = 'netstat -natv | grep "tcp4\\|tcp6\\|udp4\\|udp6"';
const states = 'ESTABLISHED|SYN_SENT|SYN_RECV|FIN_WAIT1|FIN_WAIT2|TIME_WAIT|CLOSE|CLOSE_WAIT|LAST_ACK|LISTEN|CLOSING|UNKNOWN';
exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) { exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
if (!error) { if (!error) {
@ -1509,8 +1508,9 @@ function networkConnections(callback) {
peeraddress.pop(); peeraddress.pop();
peerip = peeraddress.join('.'); peerip = peeraddress.join('.');
} }
let connstate = line[5]; const hasState = states.indexOf(line[5]) >= 0;
let pid = parseInt(line[8], 10); let connstate = hasState ? line[5] : 'UNKNOWN';
let pid = parseInt(line[8 + (hasState ? 0 : -1)], 10);
if (connstate) { if (connstate) {
result.push({ result.push({
protocol: line[0], protocol: line[0],