networkInterfaces(), cpu() improvements windows
This commit is contained in:
parent
8ef639e892
commit
d49c332d9f
@ -30,7 +30,7 @@
|
|||||||
[![Sponsoring][sponsor-badge]][sponsor-url]
|
[![Sponsoring][sponsor-badge]][sponsor-url]
|
||||||
[![MIT license][license-img]][license-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
|
## New Version 5.0
|
||||||
|
|
||||||
|
|||||||
@ -209,7 +209,7 @@
|
|||||||
<div class="title">Downloads last month</div>
|
<div class="title">Downloads last month</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
|
<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 class="title">Dependents</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
150
lib/cpu.js
150
lib/cpu.js
@ -750,88 +750,88 @@ function getCpu() {
|
|||||||
}
|
}
|
||||||
if (_windows) {
|
if (_windows) {
|
||||||
try {
|
try {
|
||||||
util.wmic('cpu get /value').then((stdout, error) => {
|
const workload = [];
|
||||||
if (!error) {
|
workload.push(util.wmic('cpu get /value'));
|
||||||
let lines = stdout.split('\r\n');
|
workload.push(util.wmic('path Win32_CacheMemory get CacheType,InstalledSize,Purpose'));
|
||||||
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(' ');
|
Promise.all(
|
||||||
for (let i = 0; i < description.length; i++) {
|
workload
|
||||||
if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) {
|
).then(data => {
|
||||||
result.family = description[i + 1];
|
let lines = data[0].split('\r\n');
|
||||||
}
|
let name = util.getValue(lines, 'name', '=') || '';
|
||||||
if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) {
|
if (name.indexOf('@') >= 0) {
|
||||||
result.model = description[i + 1];
|
result.brand = name.split('@')[0].trim();
|
||||||
}
|
result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()) : 0;
|
||||||
if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) {
|
_cpu_speed = result.speed;
|
||||||
result.stepping = description[i + 1];
|
} 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
|
if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) {
|
||||||
const socketId = util.getValue(lines, 'UpgradeMethod', '=');
|
result.model = description[i + 1];
|
||||||
if (socketTypes[socketId]) {
|
|
||||||
result.socket = socketTypes[socketId];
|
|
||||||
}
|
}
|
||||||
// # threads / # cores
|
if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) {
|
||||||
const countProcessors = util.countLines(lines, 'Caption');
|
result.stepping = description[i + 1];
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
util.wmic('path Win32_CacheMemory get CacheType,InstalledSize,Purpose').then((stdout, error) => {
|
// socket type
|
||||||
if (!error) {
|
const socketId = util.getValue(lines, 'UpgradeMethod', '=');
|
||||||
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
|
if (socketTypes[socketId]) {
|
||||||
lines.forEach(function (line) {
|
result.socket = socketTypes[socketId];
|
||||||
if (line !== '') {
|
}
|
||||||
line = line.trim().split(/\s\s+/);
|
// # threads / # cores
|
||||||
// L1 Instructions
|
const countProcessors = util.countLines(lines, 'Caption');
|
||||||
if (line[2] === 'L1 Cache' && line[0] === '3') {
|
const countThreads = util.getValue(lines, 'NumberOfLogicalProcessors', '=');
|
||||||
result.cache.l1i = parseInt(line[1], 10);
|
const countCores = util.getValue(lines, 'NumberOfCores', '=');
|
||||||
}
|
if (countProcessors) {
|
||||||
// L1 Data
|
result.processors = parseInt(countProcessors) || 1;
|
||||||
if (line[2] === 'L1 Cache' && line[0] === '4') {
|
}
|
||||||
result.cache.l1d = parseInt(line[1], 10);
|
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) {
|
} catch (e) {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
|
|||||||
@ -221,6 +221,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
|
|||||||
let netEnabled = util.getValue(lines, 'NetEnabled', '=');
|
let netEnabled = util.getValue(lines, 'NetEnabled', '=');
|
||||||
let adapterType = util.getValue(lines, 'AdapterTypeID', '=') === '9' ? 'wireless' : 'wired';
|
let adapterType = util.getValue(lines, 'AdapterTypeID', '=') === '9' ? 'wireless' : 'wired';
|
||||||
let ifacename = util.getValue(lines, 'Name', '=').replace(/\]/g, ')').replace(/\[/g, '(');
|
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) {
|
if (ifacename.toLowerCase().indexOf('wi-fi') >= 0 || ifacename.toLowerCase().indexOf('wireless') >= 0) {
|
||||||
adapterType = 'wireless';
|
adapterType = 'wireless';
|
||||||
}
|
}
|
||||||
@ -230,6 +231,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
|
|||||||
mac: util.getValue(lines, 'MACAddress', '=').toLowerCase(),
|
mac: util.getValue(lines, 'MACAddress', '=').toLowerCase(),
|
||||||
dhcp: util.getValue(linesNicConfig, 'dhcpEnabled', '=').toLowerCase(),
|
dhcp: util.getValue(linesNicConfig, 'dhcpEnabled', '=').toLowerCase(),
|
||||||
name: ifacename,
|
name: ifacename,
|
||||||
|
iface,
|
||||||
netEnabled: netEnabled === 'TRUE',
|
netEnabled: netEnabled === 'TRUE',
|
||||||
speed: isNaN(speed) ? null : speed,
|
speed: isNaN(speed) ? null : speed,
|
||||||
operstate: util.getValue(lines, 'NetConnectionStatus', '=') === '2' ? 'up' : 'down',
|
operstate: util.getValue(lines, 'NetConnectionStatus', '=') === '2' ? 'up' : 'down',
|
||||||
@ -243,7 +245,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getWindowsNics() {
|
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';
|
const cmdnicconfig = util.getWmic() + ' nicconfig get dhcpEnabled /value';
|
||||||
try {
|
try {
|
||||||
const nsections = execSync(cmd, util.execOptsWin).split(/\n\s*\n/);
|
const nsections = execSync(cmd, util.execOptsWin).split(/\n\s*\n/);
|
||||||
@ -774,6 +776,7 @@ function networkInterfaces(callback, rescan = true) {
|
|||||||
_dhcpNics = getLinuxDHCPNics();
|
_dhcpNics = getLinuxDHCPNics();
|
||||||
}
|
}
|
||||||
for (let dev in ifaces) {
|
for (let dev in ifaces) {
|
||||||
|
let iface = dev;
|
||||||
let ip4 = '';
|
let ip4 = '';
|
||||||
let ip4subnet = '';
|
let ip4subnet = '';
|
||||||
let ip6 = '';
|
let ip6 = '';
|
||||||
@ -873,6 +876,7 @@ function networkInterfaces(callback, rescan = true) {
|
|||||||
dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, dev);
|
dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, dev);
|
||||||
nics.forEach(detail => {
|
nics.forEach(detail => {
|
||||||
if (detail.mac === mac) {
|
if (detail.mac === mac) {
|
||||||
|
iface = detail.iface || iface;
|
||||||
ifaceName = detail.name;
|
ifaceName = detail.name;
|
||||||
dhcp = detail.dhcp;
|
dhcp = detail.dhcp;
|
||||||
operstate = detail.operstate;
|
operstate = detail.operstate;
|
||||||
@ -895,7 +899,7 @@ function networkInterfaces(callback, rescan = true) {
|
|||||||
}
|
}
|
||||||
const virtual = internal ? false : testVirtualNic(dev, ifaceName, mac);
|
const virtual = internal ? false : testVirtualNic(dev, ifaceName, mac);
|
||||||
result.push({
|
result.push({
|
||||||
iface: dev,
|
iface,
|
||||||
ifaceName,
|
ifaceName,
|
||||||
ip4,
|
ip4,
|
||||||
ip4subnet,
|
ip4subnet,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user