From f6780f3c48a14a3ca864fa43b7c1f8582d9758bb Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Wed, 27 Nov 2019 17:40:14 +0100 Subject: [PATCH] networkGatewayDefault() correction win --- CHANGELOG.md | 3 ++- README.md | 2 +- docs/history.html | 5 +++++ docs/index.html | 6 +++--- docs/os.html | 2 +- lib/network.js | 32 ++++++++++++++++++++++++-------- 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eb4a3e..fc36209 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,8 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | -| 4.15.2 | 2019-11-10 | type definitions and docs update | +| 4.16.0 | 2019-11-27 | `networkGatewayDefault()` added | +| 4.15.3 | 2019-11-10 | type definitions and docs update | | 4.15.2 | 2019-11-10 | `mem()` improved calculation linux | | 4.15.1 | 2019-11-10 | `diskLayout()` added support for older lsblk versions (linux) | | 4.15.0 | 2019-11-10 | `cpu()` added governor (linux) | diff --git a/README.md b/README.md index 9fa10d1..23415c6 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | Function | Result object | Linux | BSD | Mac | Win | Sun | Comments | | --------------- | ------------- | ----- | ------- | --- | --- | --- | -------- | | si.osInfo(cb) | {...} | X | X | X | X | X | OS information | -| | platform | X | X | X | X | X | 'Linux', 'Darwin', 'Windows' | +| | platform | X | X | X | X | X | 'linux', 'darwin', 'win32', ... | | | distro | X | X | X | X | X | | | | release | X | X | X | X | X | | | | codename | | | X | | | | diff --git a/docs/history.html b/docs/history.html index 4b5c709..1f93bc1 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.16.0 + 2019-11-27 + networkGatewayDefault() added + 4.15.3 2019-11-10 diff --git a/docs/index.html b/docs/index.html index ad733b3..ca889c9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.15.3
+
Current Version: 4.16.0
@@ -191,7 +191,7 @@
-
9,445
+
9,471
Lines of code
@@ -199,7 +199,7 @@
Downloads last month
-
215
+
216
Dependends
diff --git a/docs/os.html b/docs/os.html index 7693a8a..ffcd0f3 100644 --- a/docs/os.html +++ b/docs/os.html @@ -83,7 +83,7 @@ X X X - 'Linux', 'Darwin', 'Windows' + 'linux', 'darwin', 'win32', ... diff --git a/lib/network.js b/lib/network.js index 61afdb5..28126fa 100644 --- a/lib/network.js +++ b/lib/network.js @@ -1051,16 +1051,33 @@ function networkGatewayDefault(callback) { } if (_windows) { try { - util.powerShell('Get-CimInstance -ClassName Win32_IP4RouteTable | Where-Object { $_.Destination -eq \'0.0.0.0\' -and $_.Mask -eq \'0.0.0.0\' }).InterfaceIndex') + util.powerShell('Get-CimInstance -ClassName Win32_IP4RouteTable | Where-Object { $_.Destination -eq \'0.0.0.0\' -and $_.Mask -eq \'0.0.0.0\' }') .then(data => { let lines = data.toString().split('\r\n'); - result = lines && lines[0] ? lines[0] : ''; - if (callback) { - callback(result); - } - resolve(result); + if (lines.length > 1 && !result) { + result = util.getValue(lines, 'NextHop'); + // result = lines && lines[0] ? lines[0] : ''; + if (callback) { + callback(result); + } + resolve(result); + } else { + exec('ipconfig', util.execOptsWin, function (error, stdout) { + let lines = stdout.toString().split('\r\n'); + lines.forEach(function (line) { + line = line.trim().replace(/\. /g, ''); + line = line.trim().replace(/ +/g, ''); + const parts = line.split(':'); + if (parts[0].toLowerCase().startsWith('standardgate') && parts[1]) { + result = parts[1]; + } + }); + if (callback) { callback(result); } + resolve(result); + }); - }); + } + }) } catch (e) { if (callback) { callback(result); } resolve(result); @@ -1070,5 +1087,4 @@ function networkGatewayDefault(callback) { }); } - exports.networkGatewayDefault = networkGatewayDefault;