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