From b0308d4efbd28882f4263b629bbe983d2637d1ef Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Mon, 6 Jan 2020 22:34:53 +0100 Subject: [PATCH] networkInterfaces() added DHCP status mac OS --- lib/network.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/network.js b/lib/network.js index 9529725..abab9bf 100644 --- a/lib/network.js +++ b/lib/network.js @@ -486,7 +486,7 @@ function getLinuxIfaceConnectionName(interfaceName) { } } -function getLinuxDHCPnNics() { +function getLinuxDHCPNics() { // alternate methods getting interfaces using DHCP let cmd = 'ip a'; let result = []; @@ -563,6 +563,20 @@ function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) { } } +function getDarwinIfaceDHCPstatus(iface) { + let result = false; + const cmd = `ipconfig getpacket "${iface}" 2>/dev/null \| grep lease_time;`; + try { + const lines = execSync(cmd).toString().split('\n'); + if (lines.length && lines[0].startsWith('lease_time')) { + result = true; + } + } catch (e) { + util.noop(); + } + return result; +} + function getLinuxIfaceDNSsuffix(connectionName) { if (connectionName) { const cmd = `nmcli connection show "${connectionName}" 2>/dev/null \| grep ipv4.dns-search;`; @@ -651,7 +665,7 @@ function networkInterfaces(callback) { duplex: nic.duplex, mtu: nic.mtu, speed: nic.speed, - dhcp: false, + dhcp: getDarwinIfaceDHCPstatus(nic.iface), dnsSuffix: '', ieee8021xAuth: '', ieee8021xState: '', @@ -675,7 +689,7 @@ function networkInterfaces(callback) { dnsSuffixes = getWindowsDNSsuffixes(); } if (_linux) { - _dhcpNics = getLinuxDHCPnNics(); + _dhcpNics = getLinuxDHCPNics(); } for (let dev in ifaces) { let ip4 = '';