getDNS suffix on windows

This commit is contained in:
ricardopolo 2019-11-01 11:29:54 -05:00
parent 03eae68972
commit f6a95d3c45

View File

@ -224,6 +224,72 @@ function getWindowsNics() {
}
}
function getWindowsDNSsuffixes() {
let iface = {};
let dnsSuffixes = {
primaryDNS: '',
exitCode: 0,
ifaces: [],
};
try {
const ipconfig = execSync('ipconfig /all', util.execOptsWin);
const ipconfigArray = ipconfig.output.split('\r\n\r\n');
ipconfigArray.forEach( (element, index) => {
if(index == 1) {
const longPrimaryDNS = element.split('\r\n').filter((element) => {
return element.toUpperCase().includes('DNS');
});
const primaryDNS = longPrimaryDNS[0].substring(longPrimaryDNS[0].lastIndexOf(":")+1);
dnsSuffixes.primaryDNS = primaryDNS.trim();
if(!dnsSuffixes.primaryDNS) dnsSuffixes.primaryDNS = 'not defined';
}
if(index > 1) {
if(index % 2 == 0){
const name = element.substring(element.lastIndexOf(" ")+1).replace(':', '');
iface.name = name;
}else {
const connectionSpecificDNS = element.split('\r\n').filter((element) => {
return element.toUpperCase().includes('DNS')
});
const dnsSuffix = connectionSpecificDNS[0].substring(connectionSpecificDNS[0].lastIndexOf(":")+1);
iface.dnsSuffix = dnsSuffix.trim();
dnsSuffixes.ifaces.push(iface);
iface = {};
}
}
});
return dnsSuffixes;
} catch (error) {
console.log('An error occurred trying to bring the DNS suffixes of the network ifaces', error.message);
return {
primaryDNS: '',
exitCode: 0,
ifaces: [],
};
}
}
function getWindowsIfaceDNSsuffix(ifaces, ifacename) {
let dnsSuffix = '';
try {
const connectionDnsSuffix = ifaces.filter((iface) => {
return ifacename.includes(iface.name);
}).map((iface) => iface.dnsSuffix);
if(connectionDnsSuffix[0]) {
dnsSuffix = connectionDnsSuffix[0];
}
if(!dnsSuffix) dnsSuffix = 'not defined';
return dnsSuffix ;
} catch (error) {
console.log('Error getting Connection-specific DNS suffix: ', error.message);
return '';
}
}
function splitSectionsNics(lines) {
const result = [];
let section = [];
@ -351,6 +417,8 @@ function getInterfaceDHCPstatus(connectionName) {
}
}
function getInterfaceDNSsuffix(connectionName) {
if(connectionName) {
const cmd = `nmcli connection show "${connectionName}" \| grep ipv4.dns-search;`;
@ -389,6 +457,7 @@ function networkInterfaces(callback) {
let ifaces = os.networkInterfaces();
let result = [];
let nics = [];
let dnsSuffixes = [];
// seperate handling in OSX
if (_darwin || _freebsd || _openbsd || _netbsd) {
nics = getDarwinNics();
@ -424,6 +493,7 @@ function networkInterfaces(callback) {
_ifaces = ifaces;
if (_windows) {
nics = getWindowsNics();
dnsSuffixes = getWindowsDNSsuffixes();
}
for (let dev in ifaces) {
let ip4 = '';
@ -514,6 +584,7 @@ function networkInterfaces(callback) {
if (iface === 'lo' || iface.startsWith('bond')) { type = 'virtual'; }
}
if (_windows) {
dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, detail.name);
nics.forEach(detail => {
if (detail.mac === mac) {
ifaceName = detail.name;