networkGatewayDefault() fixed windows 7 issue

This commit is contained in:
Sebastian Hildebrandt 2020-01-31 17:33:58 +01:00
parent 0164a65c20
commit 3c3017935e
5 changed files with 52 additions and 26 deletions

View File

@ -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 |

View File

@ -83,6 +83,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.21.1</th>
<td>2020-01-31</td>
<td><span class="code">networkGatewayDefault()</span> fixed windows 7 issue</td>
</tr>
<tr>
<th scope="row">4.21.0</th>
<td>2020-01-27</td>

View File

@ -168,7 +168,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.21.0</span></div>
<div class="version">Current Version: <span id="version">4.21.1</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">
@ -206,7 +206,7 @@
<div class="title">Downloads last month</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">242</div>
<div class="numbers">244</div>
<div class="title">Dependends</div>
</div>
</div>

View File

@ -564,7 +564,7 @@
It is determined by calculating the difference of cpu ticks between two calls of the function.</p>
<p>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 ...</p>
The second time, you should then get statistics based on cpu ticks between the two calls ...</p>
<p>So basically, your code should look like this:</p>

View File

@ -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);