etworkStats() improved scanning (mac OS)

This commit is contained in:
Sebastian Hildebrandt 2022-04-21 22:55:32 +02:00
parent 2c4d96a72e
commit d446b8d9e4
5 changed files with 68 additions and 46 deletions

View File

@ -80,6 +80,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 5.11.13 | 2022-04-21 | `etworkStats()` improved scanning (mac OS) |
| 5.11.12 | 2022-04-19 | `battery()` improved M1 support (mac OS) |
| 5.11.11 | 2022-04-19 | `networkInterfaces()` improved parsing (windows) |
| 5.11.10 | 2022-04-18 | updated docs |

View File

@ -57,6 +57,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.11.13</th>
<td>2022-04-21</td>
<td><span class="code">networkStats()</span> improved scanning (mac OS)</td>
</tr>
<tr>
<th scope="row">5.11.12</th>
<td>2022-04-19</td>

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.11.12</span></div>
<div class="version">New Version: <span id="version">5.11.13</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">

View File

@ -185,7 +185,7 @@ module.exports = function (callback) {
result.voltage = parseInt('0' + util.getValue(lines, 'voltage', '='), 10) / 1000.0;
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'applerawmaxcapacity', '='), 10) * (result.voltage || 1));
result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'applerawxcurrentcapacity', '='), 10) * (result.voltage || 1));
result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'applerawcurrentcapacity', '='), 10) * (result.voltage || 1));
result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'DesignCapacity', '='), 10) * (result.voltage || 1));
result.manufacturer = 'Apple';
result.serial = util.getValue(lines, 'BatterySerialNumber', '=');

View File

@ -108,6 +108,7 @@ function getDefaultNetworkInterface() {
if (_linux) { cmd = 'ip route 2> /dev/null | grep default | awk \'{print $5}\''; }
if (_darwin) { cmd = 'route -n get default 2>/dev/null | grep interface: | awk \'{print $2}\''; }
if (_freebsd || _openbsd || _netbsd || _sunos) { cmd = 'route get 0.0.0.0 | grep interface:'; }
// console.log('SYNC - default darwin 3');
let result = execSync(cmd);
ifacename = result.toString().split('\n')[0];
if (ifacename.indexOf(':') > -1) {
@ -172,6 +173,7 @@ function getMacAddresses() {
if (_darwin) {
try {
const cmd = '/sbin/ifconfig';
// console.log('SYNC - macAde darwin 6');
let res = execSync(cmd);
const lines = res.toString().split('\n');
for (let i = 0; i < lines.length; i++) {
@ -504,6 +506,7 @@ function parseLinesDarwinNics(sections) {
function getDarwinNics() {
const cmd = '/sbin/ifconfig -v';
try {
// console.log('SYNC - Nics darwin 12');
const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n');
const nsections = splitSectionsNics(lines);
return (parseLinesDarwinNics(nsections));
@ -622,6 +625,7 @@ function getDarwinIfaceDHCPstatus(iface) {
let result = false;
const cmd = `ipconfig getpacket "${iface}" 2>/dev/null | grep lease_time;`;
try {
// console.log('SYNC - DHCP status darwin 17');
const lines = execSync(cmd).toString().split('\n');
if (lines.length && lines[0].startsWith('lease_time')) {
result = true;
@ -713,7 +717,6 @@ function networkInterfaces(callback, rescan, defaultString) {
return new Promise((resolve) => {
process.nextTick(() => {
const defaultInterface = getDefaultNetworkInterface();
let ifaces = os.networkInterfaces();
@ -723,56 +726,67 @@ function networkInterfaces(callback, rescan, defaultString) {
let nics8021xInfo = [];
// seperate handling in OSX
if (_darwin || _freebsd || _openbsd || _netbsd) {
nics = getDarwinNics();
if ((JSON.stringify(ifaces) === JSON.stringify(_ifaces)) && !rescan) {
// no changes - just return object
result = _networkInterfaces;
if (callback) { callback(result); }
resolve(result);
} else {
const defaultInterface = getDefaultNetworkInterface();
_ifaces = JSON.parse(JSON.stringify(ifaces));
nics = getDarwinNics();
nics.forEach(nic => {
nics.forEach(nic => {
if ({}.hasOwnProperty.call(ifaces, nic.iface)) {
ifaces[nic.iface].forEach(function (details) {
if (details.family === 'IPv4') {
nic.ip4subnet = details.netmask;
}
if (details.family === 'IPv6') {
nic.ip6subnet = details.netmask;
}
if ({}.hasOwnProperty.call(ifaces, nic.iface)) {
ifaces[nic.iface].forEach(function (details) {
if (details.family === 'IPv4') {
nic.ip4subnet = details.netmask;
}
if (details.family === 'IPv6') {
nic.ip6subnet = details.netmask;
}
});
}
result.push({
iface: nic.iface,
ifaceName: nic.iface,
default: nic.iface === defaultInterface,
ip4: nic.ip4,
ip4subnet: nic.ip4subnet || '',
ip6: nic.ip6,
ip6subnet: nic.ip6subnet || '',
mac: nic.mac,
internal: nic.internal,
virtual: nic.internal ? false : testVirtualNic(nic.iface, nic.iface, nic.mac),
operstate: nic.operstate,
type: nic.type,
duplex: nic.duplex,
mtu: nic.mtu,
speed: nic.speed,
dhcp: getDarwinIfaceDHCPstatus(nic.iface),
dnsSuffix: '',
ieee8021xAuth: '',
ieee8021xState: '',
carrierChanges: 0
});
}
result.push({
iface: nic.iface,
ifaceName: nic.iface,
default: nic.iface === defaultInterface,
ip4: nic.ip4,
ip4subnet: nic.ip4subnet || '',
ip6: nic.ip6,
ip6subnet: nic.ip6subnet || '',
mac: nic.mac,
internal: nic.internal,
virtual: nic.internal ? false : testVirtualNic(nic.iface, nic.iface, nic.mac),
operstate: nic.operstate,
type: nic.type,
duplex: nic.duplex,
mtu: nic.mtu,
speed: nic.speed,
dhcp: getDarwinIfaceDHCPstatus(nic.iface),
dnsSuffix: '',
ieee8021xAuth: '',
ieee8021xState: '',
carrierChanges: 0
});
});
_networkInterfaces = result;
if (defaultString.toLowerCase().indexOf('default') >= 0) {
result = result.filter(item => item.default);
if (result.length > 0) {
result = result[0];
} else {
result = [];
_networkInterfaces = result;
if (defaultString.toLowerCase().indexOf('default') >= 0) {
result = result.filter(item => item.default);
if (result.length > 0) {
result = result[0];
} else {
result = [];
}
}
if (callback) { callback(result); }
resolve(result);
}
if (callback) { callback(result); }
resolve(result);
}
if (_linux) {
if ((JSON.stringify(ifaces) === JSON.stringify(_ifaces)) && !rescan) {
@ -784,6 +798,7 @@ function networkInterfaces(callback, rescan, defaultString) {
} else {
_ifaces = JSON.parse(JSON.stringify(ifaces));
_dhcpNics = getLinuxDHCPNics();
const defaultInterface = getDefaultNetworkInterface();
for (let dev in ifaces) {
let ip4 = '';
let ip4subnet = '';
@ -927,6 +942,7 @@ function networkInterfaces(callback, rescan, defaultString) {
resolve(result);
} else {
_ifaces = JSON.parse(JSON.stringify(ifaces));
const defaultInterface = getDefaultNetworkInterface();
getWindowsNics().then(function (nics) {
nics.forEach(nic => {