From 9d13697be1280827efeaffb7b0ef53383007d1c9 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Mon, 12 Mar 2018 16:43:59 +0100 Subject: [PATCH] added support for 'ip' instead of 'ifconfig' --- CHANGELOG.md | 1 + README.md | 1 + lib/index.js | 2 +- lib/network.js | 25 +++++++++++++++++++++---- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 840e0c6..16d815b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.37.5 | 2018-03-12 | added support for `ip` instead of `ifconfig` | | 3.37.4 | 2018-02-22 | bugfix windows `processes()`, `disklayout()` | | 3.37.3 | 2018-02-19 | added windows exec `windowsHide` option | | 3.37.2 | 2018-02-15 | fixed bug `battery().percent` for macOS | diff --git a/README.md b/README.md index a866a1d..8e600c2 100644 --- a/README.md +++ b/README.md @@ -560,6 +560,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra - dragonjet [dragonjet](https://github.com/dragonjet) - Adam Reis [adamreisnz](https://github.com/adamreisnz) - Jimi M [ItsJimi](https://github.com/ItsJimi) +- Git² [GitSquared](https://github.com/GitSquared) OSX Temperature: credits here are going to: diff --git a/lib/index.js b/lib/index.js index c4f9a8a..f8e2b5c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -144,7 +144,7 @@ function getStaticData(callback) { data.bios = res[1]; data.baseboard = res[2]; data.os = res[3]; - data.versions =res[4]; + data.versions = res[4]; data.cpu = res[5]; data.cpu.flags = res[6]; data.graphics = res[7]; diff --git a/lib/network.js b/lib/network.js index 629b678..5b6e59c 100644 --- a/lib/network.js +++ b/lib/network.js @@ -33,6 +33,7 @@ const opts = { let _network = {}; let _default_iface; let _mac = {}; +let isIpAvailable; function getDefaultNetworkInterface() { @@ -78,13 +79,30 @@ function getMacAddresses() { let mac = ''; let result = {}; if (_linux || _freebsd || _openbsd) { - const cmd = 'export LC_ALL=C; /sbin/ifconfig; unset LC_ALL'; + if (typeof isIpAvailable === 'undefined') { + if (fs.existsSync('/sbin/ip')) { + isIpAvailable = true; + } else { + isIpAvailable = false; + } + } + const cmd = 'export LC_ALL=C; /sbin/' + ((isIpAvailable) ? 'ip link show up' : '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] !== ' ') { - iface = lines[i].split(' ')[0]; - mac = lines[i].split('HWaddr ')[1]; + if (isIpAvailable) { + let nextline = lines[i+1].trim().split(' '); + if (nextline[0] === 'link/ether') { + iface = lines[i].split(' ')[1]; + iface = iface.slice(0, iface.length - 1); + mac = nextline[1]; + } + } else { + iface = lines[i].split(' ')[0]; + mac = lines[i].split('HWaddr ')[1]; + } + if (iface && mac) { result[iface] = mac.trim(); iface = ''; @@ -92,7 +110,6 @@ function getMacAddresses() { } } } - } if (_darwin) { const cmd = '/sbin/ifconfig';