networkInterfaces() fixed caching issue
This commit is contained in:
parent
2b038e8fcd
commit
40699b8047
@ -30,7 +30,8 @@ For major (breaking) changes - version 3 and 2 see end of page.
|
||||
|
||||
| Version | Date | Comment |
|
||||
| -------------- | -------------- | -------- |
|
||||
| 4.26.7 | 2020-05-06 | `cpuTemperature()` fixed raspberry pi sensors issue |
|
||||
| 4.26.8 | 2020-06-06 | `networkInterfaces()` fixed caching issue |
|
||||
| 4.26.7 | 2020-06-06 | `cpuTemperature()` fixed raspberry pi sensors issue |
|
||||
| 4.26.6 | 2020-06-03 | `diskLayout()` fixed issue linux |
|
||||
| 4.26.5 | 2020-05-27 | `cpuTemperature()` optimizes scanning AMD linux sensors |
|
||||
| 4.26.4 | 2020-05-21 | `cpuTemperature()` fix (BSD), code cleanup |
|
||||
|
||||
@ -83,6 +83,11 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">4.26.8</th>
|
||||
<td>2020-06-06</td>
|
||||
<td><span class="code">networkInterfaces()</span> fixed caching</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">4.26.7</th>
|
||||
<td>2020-06-06</td>
|
||||
|
||||
@ -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.26.6</span></div>
|
||||
<div class="version">Current Version: <span id="version">4.26.8</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">
|
||||
|
||||
@ -89,7 +89,21 @@ function getDefaultNetworkInterface() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_linux || _darwin || _freebsd || _openbsd || _netbsd || _sunos) {
|
||||
if (_linux) {
|
||||
let cmd = 'ip route 2> /dev/null | grep default';
|
||||
let result = execSync(cmd);
|
||||
let parts = result.toString().split('\n')[0].split(/\s+/);
|
||||
if (parts[0] === 'none' && parts[5]) {
|
||||
ifacename = parts[5];
|
||||
} else if (parts[4]) {
|
||||
ifacename = parts[4];
|
||||
}
|
||||
|
||||
if (ifacename.indexOf(':') > -1) {
|
||||
ifacename = ifacename.split(':')[1].trim();
|
||||
}
|
||||
}
|
||||
if (_darwin || _freebsd || _openbsd || _netbsd || _sunos) {
|
||||
let cmd = '';
|
||||
if (_linux) cmd = 'ip route 2> /dev/null | grep default | awk \'{print $5}\'';
|
||||
if (_darwin) cmd = 'route get 0.0.0.0 2>/dev/null | grep interface: | awk \'{print $2}\'';
|
||||
@ -663,8 +677,12 @@ function testVirtualNic(iface, ifaceName, mac) {
|
||||
} else return false;
|
||||
}
|
||||
|
||||
function networkInterfaces(callback) {
|
||||
function networkInterfaces(callback, rescan = true) {
|
||||
|
||||
if (typeof callback === "boolean") {
|
||||
rescan = callback;
|
||||
callback = null;
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let ifaces = os.networkInterfaces();
|
||||
@ -733,7 +751,7 @@ function networkInterfaces(callback) {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
} else {
|
||||
if (JSON.stringify(ifaces) === JSON.stringify(_ifaces)) {
|
||||
if ((JSON.stringify(ifaces) === JSON.stringify(_ifaces)) && !rescan) {
|
||||
// no changes - just return object
|
||||
result = _networkInterfaces;
|
||||
|
||||
@ -963,7 +981,7 @@ function networkStats(ifaces, callback) {
|
||||
const workload = [];
|
||||
if (ifacesArray.length && ifacesArray[0].trim() === '*') {
|
||||
ifacesArray = [];
|
||||
networkInterfaces().then(allIFaces => {
|
||||
networkInterfaces(false).then(allIFaces => {
|
||||
for (let iface of allIFaces) {
|
||||
ifacesArray.push(iface.iface);
|
||||
}
|
||||
@ -1137,7 +1155,7 @@ function networkStatsSingle(iface) {
|
||||
}
|
||||
|
||||
// Network Interfaces
|
||||
networkInterfaces().then(interfaces => {
|
||||
networkInterfaces(false).then(interfaces => {
|
||||
// get bytes sent, received from perfData by name
|
||||
rx_bytes = 0;
|
||||
tx_bytes = 0;
|
||||
@ -1147,8 +1165,8 @@ function networkStatsSingle(iface) {
|
||||
det.mac.toLowerCase() === ifaceSanitized.toLowerCase() ||
|
||||
det.ip4.toLowerCase() === ifaceSanitized.toLowerCase() ||
|
||||
det.ip6.toLowerCase() === ifaceSanitized.toLowerCase() ||
|
||||
(det.ifaceName.replace(/[()\[\] ]+/g, '').toLowerCase() === ifaceSanitized.replace(/[()\[\] ]+/g, '').toLowerCase()) &&
|
||||
det.ifaceName.replace(/[()\[\] ]+/g, '').toLowerCase() === detail.name)) {
|
||||
det.ifaceName.replace(/[()\[\] ]+/g, '').toLowerCase() === ifaceSanitized.replace(/[()\[\] ]+/g, '').toLowerCase()) &&
|
||||
(det.ifaceName.replace(/[()\[\] ]+/g, '').toLowerCase() === detail.name)) {
|
||||
ifaceName = det.iface;
|
||||
rx_bytes = detail.rx_bytes;
|
||||
rx_dropped = detail.rx_dropped;
|
||||
@ -1160,7 +1178,6 @@ function networkStatsSingle(iface) {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (rx_bytes && tx_bytes) {
|
||||
result = calcNetworkSpeed(ifaceName, parseInt(rx_bytes), parseInt(tx_bytes), operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user