diff --git a/lib/network.js b/lib/network.js index 1eb6314..c1893f9 100644 --- a/lib/network.js +++ b/lib/network.js @@ -59,6 +59,23 @@ function getDefaultNetworkInterface() { } } ifacename = ifacename || ifacenameFirst || ''; + + if (_windows) { + // https://www.inetdaemon.com/tutorials/internet/ip/routing/default_route.shtml + const cmd = 'netstat -r'; + const result = execSync(cmd); + const lines = result.toString().split(os.EOL)[0]; + const defaultIp = util.getValue('Default Gateway', lines, ':'); + for (let dev in ifaces) { + if (ifaces.hasOwnProperty(dev)) { + ifaces[dev].forEach(function (details) { + if (details && details.address && details.address === defaultIp) { + ifacename = dev; + } + }); + } + } + } if (_linux || _darwin || _freebsd || _openbsd || _netbsd || _sunos) { let cmd = ''; if (_linux) cmd = 'ip route 2> /dev/null | grep default | awk \'{print $5}\'';