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