added support for 'ip' instead of 'ifconfig'
This commit is contained in:
+1
-1
@@ -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];
|
||||
|
||||
+21
-4
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user