networkInterface() virtual interfaces macos, networkInterfaceDefault() optimization Win

This commit is contained in:
Sebastian Hildebrandt
2019-06-24 17:15:07 +02:00
parent 6bc333c397
commit ed9203a367
4 changed files with 31 additions and 19 deletions
+22 -17
View File
@@ -64,15 +64,26 @@ function getDefaultNetworkInterface() {
// 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;
}
});
const lines = result.toString().split(os.EOL);
let defaultIp = '';
lines.forEach(line => {
line = line.replace(/\s+/g, ' ').trim();
if (line.indexOf('0.0.0.0 0.0.0.0') > -1 && !(/[a-zA-Z]/.test(line))) {
const parts = line.split(' ');
if (parts.length >= 5) {
defaultIp = parts[parts.length - 2];
}
}
})
if (defaultIp) {
for (let dev in ifaces) {
if (ifaces.hasOwnProperty(dev)) {
ifaces[dev].forEach(function (details) {
if (details && details.address && details.address === defaultIp) {
ifacename = dev;
}
});
}
}
}
}
@@ -330,7 +341,7 @@ function networkInterfaces(callback) {
ip6: nic.ip6,
mac: nic.mac,
internal: nic.internal,
virtual: testVirtualNic(nic.iface, nic.iface, nic.mac),
virtual: nic.internal ? false : testVirtualNic(nic.iface, nic.iface, nic.mac),
operstate: nic.operstate,
type: nic.type,
duplex: nic.duplex,
@@ -432,12 +443,6 @@ function networkInterfaces(callback) {
operstate = util.getValue(lines, 'operstate');
type = operstate === 'up' ? (util.getValue(lines, 'wireless').trim() ? 'wireless' : 'wired') : 'unknown';
if (iface === 'lo' || iface.startsWith('bond')) { type = 'virtual'; }
// rx_bytes = parseInt(util.getValue(lines, 'rx_bytes'), 10);
// rx_dropped = parseInt(util.getValue(lines, 'rx_dropped'), 10);
// rx_errors = parseInt(util.getValue(lines, 'rx_errors'), 10);
// tx_bytes = parseInt(util.getValue(lines, 'tx_bytes'), 10);
// tx_dropped = parseInt(util.getValue(lines, 'tx_dropped'), 10);
// tx_errors = parseInt(util.getValue(lines, 'tx_errors'), 10);
}
if (_windows) {
nics.forEach(detail => {
@@ -453,7 +458,7 @@ function networkInterfaces(callback) {
}
}
let internal = (ifaces[dev] && ifaces[dev][0]) ? ifaces[dev][0].internal : null;
const virtual = testVirtualNic(dev, ifaceName, mac);
const virtual = internal ? false : testVirtualNic(dev, ifaceName, mac);
result.push({
iface: dev,
ifaceName,