From b90c1c8a970574e671e4636d997f037d35fd2b3c Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 23 Jun 2019 17:22:57 +0200 Subject: [PATCH] default interface name windows optimization --- lib/network.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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}\'';