From 32672755b2f68080ea1c97acf0c9ac2d365bc8b1 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 10 Feb 2019 10:19:59 +0100 Subject: [PATCH] networkInterfaceDefault() fix windows --- CHANGELOG.md | 1 + README.md | 6 +++--- docs/general.html | 4 ++-- docs/history.html | 5 +++++ docs/index.html | 2 +- docs/styles.css | 2 +- docs/styles.scss | 2 +- lib/network.js | 14 ++++++++++---- 8 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c79c761..b50f5e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.0.10 | 2019-02-10 | `networkInterfaceDefault()` fix windows | | 4.0.9 | 2019-02-08 | `cpu()` fix, code cleanup | | 4.0.8 | 2019-02-05 | `inetLatency()` Windows fix parse chinese output | | 4.0.7 | 2019-02-05 | `inetLatency()` Windows fix | diff --git a/README.md b/README.md index 44c0bae..03e9cb6 100644 --- a/README.md +++ b/README.md @@ -413,7 +413,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | [0].speed | X | | | X | | speed in MBit / s | | | [0].carrierChanges | X | | | | | # changes up/down | | si.networkInterfaceDefault(cb) | : string | X | X | X | X | X | get name of default network interface | -| si.networkStats(ifaces,cb) | [{...}] | X | X | X | X | | current network stats of given interfaces
iface list: space or comma separated
iface parameter is optional
defaults to first external network interface,
pass '*' for all interfaces | +| si.networkStats(ifaces,cb) | [{...}] | X | X | X | X | | current network stats of given interfaces
iface list: space or comma separated
iface parameter is optional
defaults to first external network interface,
Pass '*' for all interfaces | | | [0].iface | X | X | X | X | | interface | | | [0].operstate | X | X | X | X | | up / down | | | [0].rx_bytes | X | X | X | X | | received bytes overall | @@ -490,8 +490,8 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | Function | Result object | Linux | BSD | Mac | Win | Sun | Comments | | --------------- | ------------- | ----- | ------- | --- | --- | --- | -------- | | si.getStaticData(cb) | {...} | X | X | X | X | X | all static data at once | -| si.getDynamicData(srv,iface,cb) | {...} | X | X | X | X | X | all dynamic data at once | -| si.getAllData(srv,iface,cb) | {...} | X | X | X | X | X | all data at once | +| si.getDynamicData(srv,iface,cb) | {...} | X | X | X | X | X | all dynamic data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces | +| si.getAllData(srv,iface,cb) | {...} | X | X | X | X | X | all data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces | ### cb: Asynchronous Function Calls (callback) diff --git a/docs/general.html b/docs/general.html index 80dec54..276b416 100644 --- a/docs/general.html +++ b/docs/general.html @@ -162,7 +162,7 @@ X X X - all dynamic data at once + all dynamic data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces si.getAllData(srv,iface,cb) @@ -172,7 +172,7 @@ X X X - all data at once + all data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces diff --git a/docs/history.html b/docs/history.html index 15569b3..75be1f9 100644 --- a/docs/history.html +++ b/docs/history.html @@ -80,6 +80,11 @@ + + 4.0.10 + 2019-02-10 + networkInterfaceDefault() fix windows + 4.0.9 2019-02-08 diff --git a/docs/index.html b/docs/index.html index 0f91a3a..08b7f4d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
-
Current Version: 4.0.9
+
Current Version: 4.0.10
diff --git a/docs/styles.css b/docs/styles.css index 7523603..9aef383 100644 --- a/docs/styles.css +++ b/docs/styles.css @@ -215,7 +215,7 @@ h1, h2, h3, h4 { .nav .logo { width: 60px; - margin-top: 10px; + margin-top: 12px; } .nav .title { diff --git a/docs/styles.scss b/docs/styles.scss index 33dd68a..ef83571 100644 --- a/docs/styles.scss +++ b/docs/styles.scss @@ -144,7 +144,7 @@ h1, h2, h3, h4 { position: relative; .logo { width: 60px; - margin-top: 10px; + margin-top: 12px; } .title { display: none; diff --git a/lib/network.js b/lib/network.js index 9aee384..1fdd8d1 100644 --- a/lib/network.js +++ b/lib/network.js @@ -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}\'';