From 03eae68972bfe899884a63454820ec2a8b5da921 Mon Sep 17 00:00:00 2001 From: ricardopolo Date: Fri, 1 Nov 2019 10:33:33 -0500 Subject: [PATCH] get DNS Suffix --- lib/network.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/network.js b/lib/network.js index 13b9b32..ae0d5ae 100644 --- a/lib/network.js +++ b/lib/network.js @@ -325,7 +325,7 @@ function getInterfaceConnectionName(interfaceName) { } } -function getDHCPstatus(connectionName) { +function getInterfaceDHCPstatus(connectionName) { if(connectionName) { const cmd = `nmcli connection show "${connectionName}" \| grep ipv4.method;`; try { @@ -351,7 +351,21 @@ function getDHCPstatus(connectionName) { } } - +function getInterfaceDNSsuffix(connectionName) { + if(connectionName) { + const cmd = `nmcli connection show "${connectionName}" \| grep ipv4.dns-search;`; + try { + const result = execSync(cmd).toString(); + const resultFormat = result.replace(/\s+/g,' ').trim(); + const dnsSuffix = resultFormat.split(" ").slice(1).toString(); + return dnsSuffix; + } catch (e) { + return 'Unknow'; + } + } else { + return 'Unknow'; + } +} 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']; @@ -421,6 +435,7 @@ function networkInterfaces(callback) { let carrierChanges = 0; let operstate = 'down'; let dhcp = false; + let dnsSuffix = ''; let type = ''; if (ifaces.hasOwnProperty(dev)) { @@ -475,7 +490,8 @@ function networkInterfaces(callback) { try { const connectionName = getInterfaceConnectionName(iface); - dhcp = getDHCPstatus(connectionName); + dhcp = getInterfaceDHCPstatus(connectionName); + dnsSuffix = getInterfaceDNSsuffix(connectionName); lines = execSync(cmd).toString().split('\n'); @@ -527,6 +543,7 @@ function networkInterfaces(callback) { mtu, speed, dhcp, + dnsSuffix, carrierChanges, }); }