diff --git a/README.md b/README.md index d287483..8fad89e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/index.html b/docs/index.html index 4ba67fa..a988e34 100644 --- a/docs/index.html +++ b/docs/index.html @@ -209,7 +209,7 @@
Downloads last month
-
390
+
393
Dependents
diff --git a/lib/cpu.js b/lib/cpu.js index 5c1dbc7..6476301 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -750,88 +750,88 @@ function getCpu() { } if (_windows) { try { - util.wmic('cpu get /value').then((stdout, error) => { - if (!error) { - let lines = stdout.split('\r\n'); - let name = util.getValue(lines, 'name', '=') || ''; - if (name.indexOf('@') >= 0) { - result.brand = name.split('@')[0].trim(); - result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()) : 0; - _cpu_speed = result.speed; - } else { - result.brand = name.trim(); - result.speed = 0; - } - result = cpuBrandManufacturer(result); - result.revision = util.getValue(lines, 'revision', '='); - result.cache.l1d = 0; - result.cache.l1i = 0; - result.cache.l2 = util.getValue(lines, 'l2cachesize', '='); - result.cache.l3 = util.getValue(lines, 'l3cachesize', '='); - if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2, 10) * 1024; } - if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3, 10) * 1024; } - result.vendor = util.getValue(lines, 'manufacturer', '='); - result.speedMax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', '=').replace(/,/g, '.')) / 10.0) / 100; - if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) { - result.speed = getAMDSpeed(result.brand); - } - if (result.speed === 0) { - result.speed = result.speedMax; - } - result.speedMin = result.speed; + const workload = []; + workload.push(util.wmic('cpu get /value')); + workload.push(util.wmic('path Win32_CacheMemory get CacheType,InstalledSize,Purpose')); - let description = util.getValue(lines, 'description', '=').split(' '); - for (let i = 0; i < description.length; i++) { - if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) { - result.family = description[i + 1]; - } - if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) { - result.model = description[i + 1]; - } - if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) { - result.stepping = description[i + 1]; - } + 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(); + result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()) : 0; + _cpu_speed = result.speed; + } else { + result.brand = name.trim(); + result.speed = 0; + } + result = cpuBrandManufacturer(result); + result.revision = util.getValue(lines, 'revision', '='); + result.cache.l1d = 0; + result.cache.l1i = 0; + result.cache.l2 = util.getValue(lines, 'l2cachesize', '='); + result.cache.l3 = util.getValue(lines, 'l3cachesize', '='); + if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2, 10) * 1024; } + if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3, 10) * 1024; } + result.vendor = util.getValue(lines, 'manufacturer', '='); + result.speedMax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', '=').replace(/,/g, '.')) / 10.0) / 100; + if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) { + result.speed = getAMDSpeed(result.brand); + } + if (result.speed === 0) { + result.speed = result.speedMax; + } + result.speedMin = result.speed; + + let description = util.getValue(lines, 'description', '=').split(' '); + for (let i = 0; i < description.length; i++) { + if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) { + result.family = description[i + 1]; } - // socket type - const socketId = util.getValue(lines, 'UpgradeMethod', '='); - if (socketTypes[socketId]) { - result.socket = socketTypes[socketId]; + if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) { + result.model = description[i + 1]; } - // # threads / # cores - const countProcessors = util.countLines(lines, 'Caption'); - const countThreads = util.getValue(lines, 'NumberOfLogicalProcessors', '='); - const countCores = util.getValue(lines, 'NumberOfCores', '='); - if (countProcessors) { - result.processors = parseInt(countProcessors) || 1; - } - if (countCores && countThreads) { - result.cores = parseInt(countThreads) || util.cores(); - result.physicalCores = parseInt(countCores) || util.cores(); - } - if (countProcessors > 1) { - result.cores = result.cores * countProcessors; - result.physicalCores = result.physicalCores * countProcessors; + if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) { + result.stepping = description[i + 1]; } } - 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.forEach(function (line) { - if (line !== '') { - line = line.trim().split(/\s\s+/); - // L1 Instructions - if (line[2] === 'L1 Cache' && line[0] === '3') { - result.cache.l1i = parseInt(line[1], 10); - } - // L1 Data - if (line[2] === 'L1 Cache' && line[0] === '4') { - result.cache.l1d = parseInt(line[1], 10); - } - } - }); + // socket type + const socketId = util.getValue(lines, 'UpgradeMethod', '='); + if (socketTypes[socketId]) { + result.socket = socketTypes[socketId]; + } + // # threads / # cores + const countProcessors = util.countLines(lines, 'Caption'); + const countThreads = util.getValue(lines, 'NumberOfLogicalProcessors', '='); + const countCores = util.getValue(lines, 'NumberOfCores', '='); + if (countProcessors) { + result.processors = parseInt(countProcessors) || 1; + } + if (countCores && countThreads) { + result.cores = parseInt(countThreads) || util.cores(); + result.physicalCores = parseInt(countCores) || util.cores(); + } + if (countProcessors > 1) { + result.cores = result.cores * countProcessors; + result.physicalCores = result.physicalCores * countProcessors; + } + 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+/); + // L1 Instructions + if (line[2] === 'L1 Cache' && line[0] === '3') { + result.cache.l1i = parseInt(line[1], 10); + } + // L1 Data + if (line[2] === 'L1 Cache' && line[0] === '4') { + result.cache.l1d = parseInt(line[1], 10); + } } - resolve(result); }); + resolve(result); }); } catch (e) { resolve(result); diff --git a/lib/network.js b/lib/network.js index 34cfa0a..9e1087b 100644 --- a/lib/network.js +++ b/lib/network.js @@ -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,