From 73a2ad62b1a78c17048a8c14f99952fe78146f2c Mon Sep 17 00:00:00 2001 From: ricardopolo Date: Wed, 30 Oct 2019 17:40:40 -0500 Subject: [PATCH] get DHCP status in linux --- lib/network.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/network.js b/lib/network.js index 8be1323..11c0d5f 100644 --- a/lib/network.js +++ b/lib/network.js @@ -317,6 +317,31 @@ function getDarwinNics() { } } + +function getNicDHCPstatus(interfaceName) { + const cmd = `nmcli con sh "${interfaceName}" | grep ipv4.method`; + console.log(cmd); + try { + let dhcpStatus = ""; + const lines = execSync(cmd, util.execOptsWin).toString().split('\n'); + const nsections = splitSectionsNics(lines); + console.log(nsections); + switch (key) { + case "auto": + dhcpStatus = "true"; + break; + + default: + dhcpStatus = "false"; + break; + } + return dhcpStatus; + } catch (e) { + return []; + } +} + + function testVirtualNic(iface, ifaceName, mac) { const virtualMacs = ['00:00:00:00:00:00', '00:03:FF', '00:05:69', '00:0C:29', '00:0F:4B', '00:0F:4B', '00:13:07', '00:13:BE', '00:15:5d', '00:16:3E', '00:1C:42', '00:21:F6', '00:21:F6', '00:24:0B', '00:24:0B', '00:50:56', '00:A0:B1', '00:E0:C8', '08:00:27', '0A:00:27', '18:92:2C', '16:DF:49', '3C:F3:92', '54:52:00', 'FC:15:97']; if (mac) { @@ -342,11 +367,11 @@ function networkInterfaces(callback) { // seperate handling in OSX if (_darwin || _freebsd || _openbsd || _netbsd) { nics = getDarwinNics(); - // console.log(nics); - // console.log('-------'); - // console.log(ifaces); + nics.forEach(nic => { + dhcpStatus = getNicDHCPstatus(nic.iface); + result.push({ iface: nic.iface, ifaceName: nic.iface, @@ -358,6 +383,7 @@ function networkInterfaces(callback) { operstate: nic.operstate, type: nic.type, duplex: nic.duplex, + dhcpStatus: dhcpStatus, mtu: nic.mtu, speed: nic.speed, carrierChanges: 0