networkInterfaceDefault() fix windows
This commit is contained in:
+10
-4
@@ -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}\'';
|
||||
|
||||
Reference in New Issue
Block a user