networkInterfaces(), cpu() improvements windows

This commit is contained in:
Sebastian Hildebrandt 2021-03-09 11:58:47 +01:00
parent 8ef639e892
commit d49c332d9f
4 changed files with 83 additions and 79 deletions

View File

@ -30,7 +30,7 @@
[![Sponsoring][sponsor-badge]][sponsor-url]
[![MIT license][license-img]][license-url]
This is amazing. Started as a small project just for myself, it now has > 10,000 lines of code, > 400 versions published, > 3 mio downloads per month, > 30 mio downloads overall. Thank you to all who contributed to this project!
This is amazing. Started as a small project just for myself, it now has > 10,000 lines of code, > 400 versions published, up to 3 mio downloads per month, > 30 mio downloads overall. Thank you to all who contributed to this project!
## New Version 5.0

View File

@ -209,7 +209,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">390</div>
<div class="numbers">393</div>
<div class="title">Dependents</div>
</div>
</div>

View File

@ -750,9 +750,14 @@ function getCpu() {
}
if (_windows) {
try {
util.wmic('cpu get /value').then((stdout, error) => {
if (!error) {
let lines = stdout.split('\r\n');
const workload = [];
workload.push(util.wmic('cpu get /value'));
workload.push(util.wmic('path Win32_CacheMemory get CacheType,InstalledSize,Purpose'));
Promise.all(
workload
).then(data => {
let lines = data[0].split('\r\n');
let name = util.getValue(lines, 'name', '=') || '';
if (name.indexOf('@') >= 0) {
result.brand = name.split('@')[0].trim();
@ -812,10 +817,7 @@ function getCpu() {
result.cores = result.cores * countProcessors;
result.physicalCores = result.physicalCores * countProcessors;
}
}
util.wmic('path Win32_CacheMemory get CacheType,InstalledSize,Purpose').then((stdout, error) => {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines = data[1].split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
line = line.trim().split(/\s\s+/);
@ -829,10 +831,8 @@ function getCpu() {
}
}
});
}
resolve(result);
});
});
} catch (e) {
resolve(result);
}

View File

@ -221,6 +221,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
let netEnabled = util.getValue(lines, 'NetEnabled', '=');
let adapterType = util.getValue(lines, 'AdapterTypeID', '=') === '9' ? 'wireless' : 'wired';
let ifacename = util.getValue(lines, 'Name', '=').replace(/\]/g, ')').replace(/\[/g, '(');
let iface = util.getValue(lines, 'NetConnectionID', '=').replace(/\]/g, ')').replace(/\[/g, '(');
if (ifacename.toLowerCase().indexOf('wi-fi') >= 0 || ifacename.toLowerCase().indexOf('wireless') >= 0) {
adapterType = 'wireless';
}
@ -230,6 +231,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
mac: util.getValue(lines, 'MACAddress', '=').toLowerCase(),
dhcp: util.getValue(linesNicConfig, 'dhcpEnabled', '=').toLowerCase(),
name: ifacename,
iface,
netEnabled: netEnabled === 'TRUE',
speed: isNaN(speed) ? null : speed,
operstate: util.getValue(lines, 'NetConnectionStatus', '=') === '2' ? 'up' : 'down',
@ -243,7 +245,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
}
function getWindowsNics() {
const cmd = util.getWmic() + ' nic get MACAddress, name, NetEnabled, Speed, NetConnectionStatus, AdapterTypeId /value';
const cmd = util.getWmic() + ' nic get MACAddress, name, NetConnectionId, NetEnabled, Speed, NetConnectionStatus, AdapterTypeId /value';
const cmdnicconfig = util.getWmic() + ' nicconfig get dhcpEnabled /value';
try {
const nsections = execSync(cmd, util.execOptsWin).split(/\n\s*\n/);
@ -774,6 +776,7 @@ function networkInterfaces(callback, rescan = true) {
_dhcpNics = getLinuxDHCPNics();
}
for (let dev in ifaces) {
let iface = dev;
let ip4 = '';
let ip4subnet = '';
let ip6 = '';
@ -873,6 +876,7 @@ function networkInterfaces(callback, rescan = true) {
dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, dev);
nics.forEach(detail => {
if (detail.mac === mac) {
iface = detail.iface || iface;
ifaceName = detail.name;
dhcp = detail.dhcp;
operstate = detail.operstate;
@ -895,7 +899,7 @@ function networkInterfaces(callback, rescan = true) {
}
const virtual = internal ? false : testVirtualNic(dev, ifaceName, mac);
result.push({
iface: dev,
iface,
ifaceName,
ip4,
ip4subnet,