getDNS suffix on windows
This commit is contained in:
parent
03eae68972
commit
f6a95d3c45
@ -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) {
|
function splitSectionsNics(lines) {
|
||||||
const result = [];
|
const result = [];
|
||||||
let section = [];
|
let section = [];
|
||||||
@ -351,6 +417,8 @@ function getInterfaceDHCPstatus(connectionName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getInterfaceDNSsuffix(connectionName) {
|
function getInterfaceDNSsuffix(connectionName) {
|
||||||
if(connectionName) {
|
if(connectionName) {
|
||||||
const cmd = `nmcli connection show "${connectionName}" \| grep ipv4.dns-search;`;
|
const cmd = `nmcli connection show "${connectionName}" \| grep ipv4.dns-search;`;
|
||||||
@ -389,6 +457,7 @@ function networkInterfaces(callback) {
|
|||||||
let ifaces = os.networkInterfaces();
|
let ifaces = os.networkInterfaces();
|
||||||
let result = [];
|
let result = [];
|
||||||
let nics = [];
|
let nics = [];
|
||||||
|
let dnsSuffixes = [];
|
||||||
// seperate handling in OSX
|
// seperate handling in OSX
|
||||||
if (_darwin || _freebsd || _openbsd || _netbsd) {
|
if (_darwin || _freebsd || _openbsd || _netbsd) {
|
||||||
nics = getDarwinNics();
|
nics = getDarwinNics();
|
||||||
@ -424,6 +493,7 @@ function networkInterfaces(callback) {
|
|||||||
_ifaces = ifaces;
|
_ifaces = ifaces;
|
||||||
if (_windows) {
|
if (_windows) {
|
||||||
nics = getWindowsNics();
|
nics = getWindowsNics();
|
||||||
|
dnsSuffixes = getWindowsDNSsuffixes();
|
||||||
}
|
}
|
||||||
for (let dev in ifaces) {
|
for (let dev in ifaces) {
|
||||||
let ip4 = '';
|
let ip4 = '';
|
||||||
@ -514,6 +584,7 @@ function networkInterfaces(callback) {
|
|||||||
if (iface === 'lo' || iface.startsWith('bond')) { type = 'virtual'; }
|
if (iface === 'lo' || iface.startsWith('bond')) { type = 'virtual'; }
|
||||||
}
|
}
|
||||||
if (_windows) {
|
if (_windows) {
|
||||||
|
dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, detail.name);
|
||||||
nics.forEach(detail => {
|
nics.forEach(detail => {
|
||||||
if (detail.mac === mac) {
|
if (detail.mac === mac) {
|
||||||
ifaceName = detail.name;
|
ifaceName = detail.name;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user