network mac adresses: ip support fix
This commit is contained in:
+13
-8
@@ -30,7 +30,7 @@ const _sunos = (_platform === 'sunos');
|
||||
let _network = {};
|
||||
let _default_iface;
|
||||
let _mac = {};
|
||||
let isIpAvailable;
|
||||
let pathToIp;
|
||||
|
||||
function getDefaultNetworkInterface() {
|
||||
|
||||
@@ -72,19 +72,24 @@ function getMacAddresses() {
|
||||
let mac = '';
|
||||
let result = {};
|
||||
if (_linux || _freebsd || _openbsd) {
|
||||
if (typeof isIpAvailable === 'undefined') {
|
||||
if (fs.existsSync('/sbin/ip')) {
|
||||
isIpAvailable = true;
|
||||
} else {
|
||||
isIpAvailable = false;
|
||||
if (typeof pathToIp === 'undefined') {
|
||||
try {
|
||||
const lines = execSync('which ip').toString().split('\n');
|
||||
if (lines.length && lines[0].indexOf(':') === -1 && lines[0].indexOf('/') === 0) {
|
||||
pathToIp = lines[0];
|
||||
} else {
|
||||
pathToIp = '';
|
||||
}
|
||||
} catch (e) {
|
||||
pathToIp = '';
|
||||
}
|
||||
}
|
||||
const cmd = 'export LC_ALL=C; /sbin/' + ((isIpAvailable) ? 'ip link show up' : 'ifconfig') + '; unset LC_ALL';
|
||||
const cmd = 'export LC_ALL=C; ' + ((pathToIp) ? pathToIp + ' link show up' : '/sbin/ifconfig') + '; unset LC_ALL';
|
||||
let res = execSync(cmd);
|
||||
const lines = res.toString().split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i] && lines[i][0] !== ' ') {
|
||||
if (isIpAvailable) {
|
||||
if (pathToIp) {
|
||||
let nextline = lines[i + 1].trim().split(' ');
|
||||
if (nextline[0] === 'link/ether') {
|
||||
iface = lines[i].split(' ')[1];
|
||||
|
||||
Reference in New Issue
Block a user