networkInterfaceDefault() fix windows

This commit is contained in:
Sebastian Hildebrandt
2019-02-10 10:19:59 +01:00
parent abf330afb5
commit 32672755b2
8 changed files with 24 additions and 12 deletions
+10 -4
View File
@@ -28,7 +28,7 @@ const _openbsd = (_platform === 'openbsd');
const _sunos = (_platform === 'sunos');
let _network = {};
let _default_iface;
let _default_iface = '';
let _ifaces = [];
let _networkInterfaces = [];
let _mac = {};
@@ -38,19 +38,25 @@ function getDefaultNetworkInterface() {
let ifaces = os.networkInterfaces();
let ifacename = '';
let ifacenameFirst = '';
let scopeid = 9999;
// fallback - "first" external interface (sorted by scopeid)
for (let dev in ifaces) {
if (ifaces.hasOwnProperty(dev)) {
ifaces[dev].forEach(function (details) {
if (details && details.internal === false && details.scopeid && details.scopeid < scopeid) {
ifacename = dev;
scopeid = details.scopeid;
if (details && details.internal === false) {
ifacenameFirst = ifacenameFirst || dev; // fallback if no scopeid
if (details.scopeid && details.scopeid < scopeid) {
ifacename = dev;
scopeid = details.scopeid;
}
}
});
}
}
ifacename = ifacename || ifacenameFirst || '';
if (_linux || _darwin || _freebsd || _openbsd || _sunos) {
let cmd = '';
if (_linux) cmd = 'route 2>/dev/null | grep default | awk \'{print $8}\'';