added legacy support for networkInterface() DHCP status
This commit is contained in:
parent
634193a75b
commit
a2046eaad1
@ -32,6 +32,7 @@ const _sunos = (_platform === 'sunos');
|
|||||||
let _network = {};
|
let _network = {};
|
||||||
let _default_iface = '';
|
let _default_iface = '';
|
||||||
let _ifaces = [];
|
let _ifaces = [];
|
||||||
|
let _dhcpNics = [];
|
||||||
let _networkInterfaces = [];
|
let _networkInterfaces = [];
|
||||||
let _mac = {};
|
let _mac = {};
|
||||||
let pathToIp;
|
let pathToIp;
|
||||||
@ -389,7 +390,7 @@ function splitSectionsNics(lines) {
|
|||||||
const result = [];
|
const result = [];
|
||||||
let section = [];
|
let section = [];
|
||||||
lines.forEach(function (line) {
|
lines.forEach(function (line) {
|
||||||
if (!line.startsWith('\t')) {
|
if (!line.startsWith('\t') && !line.startsWith(' ')) {
|
||||||
if (section.length) {
|
if (section.length) {
|
||||||
result.push(section);
|
result.push(section);
|
||||||
section = [];
|
section = [];
|
||||||
@ -463,7 +464,7 @@ function parseLinesDarwinNics(sections) {
|
|||||||
function getDarwinNics() {
|
function getDarwinNics() {
|
||||||
const cmd = '/sbin/ifconfig -v';
|
const cmd = '/sbin/ifconfig -v';
|
||||||
try {
|
try {
|
||||||
const lines = execSync(cmd, util.execOptsWin).toString().split('\n');
|
const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n');
|
||||||
const nsections = splitSectionsNics(lines);
|
const nsections = splitSectionsNics(lines);
|
||||||
return (parseLinesDarwinNics(nsections));
|
return (parseLinesDarwinNics(nsections));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -485,7 +486,57 @@ function getLinuxIfaceConnectionName(interfaceName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLinuxIfaceDHCPstatus(connectionName) {
|
function getLinuxDHCPnNics() {
|
||||||
|
// alternate methods getting interfaces using DHCP
|
||||||
|
let cmd = 'ip a';
|
||||||
|
let result = [];
|
||||||
|
try {
|
||||||
|
const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n');
|
||||||
|
const nsections = splitSectionsNics(lines);
|
||||||
|
result = (parseLinuxDHCPNics(nsections));
|
||||||
|
} catch (e) {
|
||||||
|
util.noop();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
cmd = 'cat /etc/network/interfaces | grep iface';
|
||||||
|
const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n');
|
||||||
|
lines.forEach(line => {
|
||||||
|
const parts = line.replace(/\s+/g, ' ').trim().split(' ');
|
||||||
|
if (parts.length >=4) {
|
||||||
|
if (line.toLowerCase().indexOf('dynamic') >= 0) {
|
||||||
|
result.push(parts[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
util.noop();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseLinuxDHCPNics(sections) {
|
||||||
|
const result = [];
|
||||||
|
if (sections && sections.length) {
|
||||||
|
sections.forEach(lines => {
|
||||||
|
if (lines && lines.length) {
|
||||||
|
const parts = lines[0].split(':');
|
||||||
|
if (parts.length > 2) {
|
||||||
|
for (let line of lines) {
|
||||||
|
if (line.indexOf(' inet ') >= 0 && line.indexOf(' dynamic ') >= 0) {
|
||||||
|
const parts2 = line.split(' ');
|
||||||
|
const nic = parts2[parts2.length - 1].trim();
|
||||||
|
result.push(nic);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) {
|
||||||
let result = false;
|
let result = false;
|
||||||
if (connectionName) {
|
if (connectionName) {
|
||||||
const cmd = `nmcli connection show "${connectionName}" 2>/dev/null \| grep ipv4.method;`;
|
const cmd = `nmcli connection show "${connectionName}" 2>/dev/null \| grep ipv4.method;`;
|
||||||
@ -505,7 +556,7 @@ function getLinuxIfaceDHCPstatus(connectionName) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return result;
|
return (DHCPNics.indexOf(iface) >= 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
@ -623,6 +674,9 @@ function networkInterfaces(callback) {
|
|||||||
nics = getWindowsNics();
|
nics = getWindowsNics();
|
||||||
dnsSuffixes = getWindowsDNSsuffixes();
|
dnsSuffixes = getWindowsDNSsuffixes();
|
||||||
}
|
}
|
||||||
|
if (_linux) {
|
||||||
|
_dhcpNics = getLinuxDHCPnNics();
|
||||||
|
}
|
||||||
for (let dev in ifaces) {
|
for (let dev in ifaces) {
|
||||||
let ip4 = '';
|
let ip4 = '';
|
||||||
let ip6 = '';
|
let ip6 = '';
|
||||||
@ -688,14 +742,12 @@ function networkInterfaces(callback) {
|
|||||||
|
|
||||||
let lines = [];
|
let lines = [];
|
||||||
try {
|
try {
|
||||||
|
lines = execSync(cmd).toString().split('\n');
|
||||||
const connectionName = getLinuxIfaceConnectionName(iface);
|
const connectionName = getLinuxIfaceConnectionName(iface);
|
||||||
dhcp = getLinuxIfaceDHCPstatus(connectionName);
|
dhcp = getLinuxIfaceDHCPstatus(iface, connectionName, _dhcpNics);
|
||||||
dnsSuffix = getLinuxIfaceDNSsuffix(connectionName);
|
dnsSuffix = getLinuxIfaceDNSsuffix(connectionName);
|
||||||
ieee8021xAuth = getLinuxIfaceIEEE8021xAuth(connectionName);
|
ieee8021xAuth = getLinuxIfaceIEEE8021xAuth(connectionName);
|
||||||
ieee8021xState = getLinuxIfaceIEEE8021xState(ieee8021xAuth);
|
ieee8021xState = getLinuxIfaceIEEE8021xState(ieee8021xAuth);
|
||||||
lines = execSync(cmd).toString().split('\n');
|
|
||||||
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
util.noop();
|
util.noop();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,6 @@ const execOptsWin = {
|
|||||||
env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
|
env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function toInt(value) {
|
function toInt(value) {
|
||||||
let result = parseInt(value, 10);
|
let result = parseInt(value, 10);
|
||||||
if (isNaN(result)) {
|
if (isNaN(result)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user