diff --git a/CHANGELOG.md b/CHANGELOG.md index 14fa8d6..72b8522 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.21.1 | 2020-01-31 | `networkGatewayDefault()` fixed windows 7 issue | +| 4.21.0 | 2020-01-27 | `npx` compatibility | +| 4.20.1 | 2020-01-26 | `battery()` code refactoring, cleanup, updated docs | | 4.20.1 | 2020-01-26 | `battery()` code refactoring, cleanup, updated docs | | 4.20.0 | 2020-01-25 | `battery()` added designcapacity, voltage, unit | | 4.19.4 | 2020-01-24 | `mem()` prevent log messages, `memgetDefaultNetworkInterface()` catch errors | diff --git a/docs/history.html b/docs/history.html index 6b103de..8eab5a7 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@
+
The first time you are calling one of this functions, you will get the load since cpu uptime. - The second time, you should then get statistics based cpu ticks between the two calls ...
+ The second time, you should then get statistics based on cpu ticks between the two calls ...So basically, your code should look like this:
diff --git a/lib/network.js b/lib/network.js index f25556f..0ebc31d 100644 --- a/lib/network.js +++ b/lib/network.js @@ -1402,32 +1402,50 @@ 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\' }') - .then(data => { - let lines = data.toString().split('\r\n'); - if (lines.length > 1 && !result) { - result = util.getValue(lines, 'NextHop'); - // result = lines && lines[0] ? lines[0] : ''; - if (callback) { - callback(result); + exec('netstat -r', util.execOptsWin, function (error, stdout) { + const lines = stdout.toString().split(os.EOL); + 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 && (parts[parts.length - 3]).indexOf('.') > -1) { + result = parts[parts.length - 3]; } - 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); - }); } }); + if (!result) { + 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'); + if (lines.length > 1 && !result) { + result = util.getValue(lines, 'NextHop'); + 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[0].toLowerCase().indexOf('gateway') > -1 || parts[0].toLowerCase().indexOf('enlace') > -1) && parts[1]) { + // result = parts[1]; + // } + // }); + // if (callback) { callback(result); } + // resolve(result); + // }); + } + }); + } else { + if (callback) { + callback(result); + } + resolve(result); + } + }); } catch (e) { if (callback) { callback(result); } resolve(result);