diff --git a/CHANGELOG.md b/CHANGELOG.md index af078d4..e58ee99 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.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 | diff --git a/docs/history.html b/docs/history.html index d3a73ae..fc45b25 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.26.8 + 2020-06-06 + networkInterfaces() fixed caching + 4.26.7 2020-06-06 diff --git a/docs/index.html b/docs/index.html index 8e40f22..59bc9e6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.26.6
+
Current Version: 4.26.8
diff --git a/lib/network.js b/lib/network.js index 65fc392..d9f69d1 100644 --- a/lib/network.js +++ b/lib/network.js @@ -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); }