From 1fbdeecef82807f0da4d03bd4f53294fb7fdd05b Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Fri, 23 Nov 2018 19:20:40 +0100 Subject: [PATCH] network mac adresses: ip support fix --- CHANGELOG.md | 1 + README.md | 2 +- lib/network.js | 21 +++++++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91fa140..4c082c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.50.2 | 2018-11-23 | network mac adresses: ip support fix | | 3.50.1 | 2018-11-23 | `services()` added possibility to specify ALL services "*" for win | | 3.50.0 | 2018-11-23 | `services()` added possibility to specify ALL services "*" for linux | | 3.49.4 | 2018-11-21 | `battery()` timeremaining optimization (linux) thanks to Jorai Rijsdijk | diff --git a/README.md b/README.md index bd815a6..b921422 100644 --- a/README.md +++ b/README.md @@ -378,7 +378,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | pid | X | X | X | | | PID | | | cpu | X | X | X | | | process % CPU | | | mem | X | X | X | | | process % MEM | -| si.services('mysql, apache2', cb) | [{...}] | X | X | X | X | | pass comma separated string of services
pass "*" for ALL services (linux only) | +| si.services('mysql, apache2', cb) | [{...}] | X | X | X | X | | pass comma separated string of services
pass "*" for ALL services (linux/win only) | | | [0].name | X | X | X | X | | name of service | | | [0].running | X | X | X | X | | true / false | | | [0].startmode | | | | X | | manual, automatic, ... | diff --git a/lib/network.js b/lib/network.js index 395a376..f80a92e 100644 --- a/lib/network.js +++ b/lib/network.js @@ -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];