From 18b6e8b87d1df55acbefdfcb21183fa6f47c30c6 Mon Sep 17 00:00:00 2001 From: VP-002 U <> Date: Fri, 1 Nov 2019 10:45:05 -0500 Subject: [PATCH] Get DNS Suffix in linux --- lib/network.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/network.js b/lib/network.js index ae0d5ae..8262242 100644 --- a/lib/network.js +++ b/lib/network.js @@ -311,7 +311,7 @@ function getDarwinNics() { } -function getInterfaceConnectionName(interfaceName) { +function getLinuxIfaceConnectionName(interfaceName) { const cmd = `nmcli device status | grep ${interfaceName}`; try { @@ -325,7 +325,7 @@ function getInterfaceConnectionName(interfaceName) { } } -function getInterfaceDHCPstatus(connectionName) { +function getLinuxIfaceDHCPstatus(connectionName) { if(connectionName) { const cmd = `nmcli connection show "${connectionName}" \| grep ipv4.method;`; try { @@ -351,14 +351,14 @@ function getInterfaceDHCPstatus(connectionName) { } } -function getInterfaceDNSsuffix(connectionName) { +function getLinuxIfaceDNSsuffix(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; + return dnsSuffix == '--' ? '': dnsSuffix; } catch (e) { return 'Unknow'; } @@ -489,9 +489,9 @@ function networkInterfaces(callback) { let lines = []; try { - const connectionName = getInterfaceConnectionName(iface); - dhcp = getInterfaceDHCPstatus(connectionName); - dnsSuffix = getInterfaceDNSsuffix(connectionName); + const connectionName = getLinuxIfaceConnectionName(iface); + dhcp = getLinuxIfaceDHCPstatus(connectionName); + dnsSuffix = getLinuxIfaceDNSsuffix(connectionName); lines = execSync(cmd).toString().split('\n');