added support for 'ip' instead of 'ifconfig'

This commit is contained in:
Sebastian Hildebrandt 2018-03-12 16:43:59 +01:00
parent c44e40859f
commit 9d13697be1
4 changed files with 24 additions and 5 deletions

View File

@ -100,6 +100,7 @@ Other changes
| Version | Date | Comment | | 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.4 | 2018-02-22 | bugfix windows `processes()`, `disklayout()` |
| 3.37.3 | 2018-02-19 | added windows exec `windowsHide` option | | 3.37.3 | 2018-02-19 | added windows exec `windowsHide` option |
| 3.37.2 | 2018-02-15 | fixed bug `battery().percent` for macOS | | 3.37.2 | 2018-02-15 | fixed bug `battery().percent` for macOS |

View File

@ -560,6 +560,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra
- dragonjet [dragonjet](https://github.com/dragonjet) - dragonjet [dragonjet](https://github.com/dragonjet)
- Adam Reis [adamreisnz](https://github.com/adamreisnz) - Adam Reis [adamreisnz](https://github.com/adamreisnz)
- Jimi M [ItsJimi](https://github.com/ItsJimi) - Jimi M [ItsJimi](https://github.com/ItsJimi)
- Git² [GitSquared](https://github.com/GitSquared)
OSX Temperature: credits here are going to: OSX Temperature: credits here are going to:

View File

@ -144,7 +144,7 @@ function getStaticData(callback) {
data.bios = res[1]; data.bios = res[1];
data.baseboard = res[2]; data.baseboard = res[2];
data.os = res[3]; data.os = res[3];
data.versions =res[4]; data.versions = res[4];
data.cpu = res[5]; data.cpu = res[5];
data.cpu.flags = res[6]; data.cpu.flags = res[6];
data.graphics = res[7]; data.graphics = res[7];

View File

@ -33,6 +33,7 @@ const opts = {
let _network = {}; let _network = {};
let _default_iface; let _default_iface;
let _mac = {}; let _mac = {};
let isIpAvailable;
function getDefaultNetworkInterface() { function getDefaultNetworkInterface() {
@ -78,13 +79,30 @@ function getMacAddresses() {
let mac = ''; let mac = '';
let result = {}; let result = {};
if (_linux || _freebsd || _openbsd) { 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); let res = execSync(cmd);
const lines = res.toString().split('\n'); const lines = res.toString().split('\n');
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
if (lines[i] && lines[i][0] !== ' ') { if (lines[i] && lines[i][0] !== ' ') {
iface = lines[i].split(' ')[0]; if (isIpAvailable) {
mac = lines[i].split('HWaddr ')[1]; 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) { if (iface && mac) {
result[iface] = mac.trim(); result[iface] = mac.trim();
iface = ''; iface = '';
@ -92,7 +110,6 @@ function getMacAddresses() {
} }
} }
} }
} }
if (_darwin) { if (_darwin) {
const cmd = '/sbin/ifconfig'; const cmd = '/sbin/ifconfig';