Add DHCP Status and connection DNS suffix search order

This commit is contained in:
JuanCamp 2019-10-07 15:29:13 -05:00
parent 4f1bde9ec5
commit e3b18a0f75

View File

@ -183,19 +183,29 @@ exports.networkInterfaceDefault = networkInterfaceDefault;
// --------------------------
// NET - interfaces
function parseLinesWindowsNics(sections) {
function parseLinesWindowsNics(sections, nconfigsections) {
let nics = [];
for (let i in sections) {
if (sections.hasOwnProperty(i)) {
if (sections[i].trim() !== '') {
let lines = sections[i].trim().split('\r\n');
let linesNicConfig = nconfigsections[i].trim().split('\r\n');
let netEnabled = util.getValue(lines, 'NetEnabled', '=');
let dnsSuffixes = util.getValue(linesNicConfig, 'DNSDomainSuffixSearchOrder', '=').replace(/{|}/g, '');
if(dnsSuffixes !== '') {
dnsSuffixes = dnsSuffixes.replace(/;/g, ',');
dnsSuffixes = dnsSuffixes.split(",");
}
if (netEnabled) {
const speed = parseInt(util.getValue(lines, 'speed', '=').trim(), 10) / 1000000;
nics.push({
mac: util.getValue(lines, 'MACAddress', '=').toLowerCase(),
dhcp: util.getValue(linesNicConfig, 'dhcpEnabled', '=').toLowerCase(),
name: util.getValue(lines, 'Name', '=').replace(/\]/g, ')').replace(/\[/g, '('),
dnsSuffixes: dnsSuffixes === '' ? [] : dnsSuffixes,
netEnabled: netEnabled === 'TRUE',
speed: isNaN(speed) ? -1 : speed,
operstate: util.getValue(lines, 'NetConnectionStatus', '=') === '2' ? 'up' : 'down',
@ -210,9 +220,11 @@ function parseLinesWindowsNics(sections) {
function getWindowsNics() {
const cmd = util.getWmic() + ' nic get MACAddress, name, NetEnabled, Speed, NetConnectionStatus, AdapterTypeId /value';
const cmdnicconfig = util.getWmic() + ' nicconfig get dhcpEnabled, DNSDomainSuffixSearchOrder /value';
try {
const nsections = execSync(cmd, util.execOptsWin).split(/\n\s*\n/);
return (parseLinesWindowsNics(nsections));
const nconfigsections = execSync(cmdnicconfig, util.execOptsWin).split(/\n\s*\n/);
return (parseLinesWindowsNics(nsections, nconfigsections));
} catch (e) {
return [];
}
@ -373,12 +385,13 @@ function networkInterfaces(callback) {
let speed = -1;
let carrierChanges = 0;
let operstate = 'down';
let dhcp = false;
let dnsSuffixes = [];
let type = '';
if (ifaces.hasOwnProperty(dev)) {
let ifaceName = dev;
ifaces[dev].forEach(function (details) {
if (details.family === 'IPv4') {
ip4 = details.address;
}
@ -426,6 +439,7 @@ function networkInterfaces(callback) {
let lines = [];
try {
lines = execSync(cmd).toString().split('\n');
} catch (e) {
util.noop();
}
@ -448,6 +462,8 @@ function networkInterfaces(callback) {
nics.forEach(detail => {
if (detail.mac === mac) {
ifaceName = detail.name;
dhcp = detail.dhcp;
dnsSuffixes = detail.dnsSuffixes;
operstate = detail.operstate;
speed = detail.speed;
type = detail.type;
@ -472,6 +488,8 @@ function networkInterfaces(callback) {
duplex,
mtu,
speed,
dhcp,
dnsSuffixes,
carrierChanges,
});
}