没事使用node的第三方依赖库来获取电脑的配置信息,主要是获取cpu,操作系统,磁盘,网络接口等信息
npm install systeminformation
效果
CPU信息:
- 制造商: Intel
- 品牌: Core™ i5-6500
- 速度: 3.2GHz
- 核心数: 4
- 物理核心数: 4
内存信息:
- 总计: 15.91GB
- 空闲: 5.24GB
操作系统信息:
- 平台: Windows
- 发行版: Microsoft Windows 10 专业版
- 版本: 10.0.19045
磁盘信息:
- 磁盘 0:
- 类型: HD
- 名称: WDC WD10EZEX-00WN4A0
- 接口类型: SATA
- 大小: 931.51GB
- 磁盘 1:
- 类型: SSD
- 名称: SAMSUNG MZNTE128HMGR-00000
- 接口类型: SATA
- 大小: 119.24GB
网络接口信息:
- 接口 0:
- 名称: 以太网
- 型号: undefined
- MAC地址: d0:17:c2:94:e6:c5
- IPv4地址: 192.168.12.13
- IPv6地址: 240e:3b2:32d0:c5e0::1018
- 接口 1:
- 名称: VMware Network Adapter VMnet1
- 型号: undefined
- MAC地址: 00:50:16:c0:00:01
- IPv4地址: 192.168.64.123
- IPv6地址: fe80::6f7d:3c95:8237:4fed
- 接口 2:
- 名称: VMware Network Adapter VMnet8
- 型号: undefined
- MAC地址: 00:50:51:c0:00:08
- IPv4地址: 192.168.206.12
- IPv6地址: fe80::f20b:f90b:e773:55c
- 接口 3:
- 名称: Loopback Pseudo-Interface 1
- 型号: undefined
- MAC地址: 00:00:00:00:00:00
- IPv4地址: 127.0.0.1
- IPv6地址: ::1
- 接口 4:
- 名称: vEthernet (Default Switch)
- 型号: undefined
- MAC地址: 02:15:5d:33:3d:bb
- IPv4地址: 172.24.28.12
- IPv6地址: fe80::c46c:7e85:a54f:8dea
-----电脑信息获取完毕!!
实现的代码
/*
* @Descripttion: 电脑信息展示
* @Author: lihk
* @Date: 2024-03-18 11:26:05
*/
import si from 'systeminformation';
async function displaySystemInfo () {
try {
// CPU信息
const cpu = await si.cpu();
console.log('CPU信息:');
console.log(`- 制造商: ${cpu.manufacturer}`);
console.log(`- 品牌: ${cpu.brand}`);
console.log(`- 速度: ${cpu.speed}GHz`);
console.log(`- 核心数: ${cpu.cores}`);
console.log(`- 物理核心数: ${cpu.physicalCores}`);
console.log('');
// 内存信息
const mem = await si.mem();
console.log('内存信息:');
console.log(`- 总计: ${(mem.total / 1024 / 1024 / 1024).toFixed(2)}GB`);
console.log(`- 空闲: ${(mem.free / 1024 / 1024 / 1024).toFixed(2)}GB`);
console.log('');
// 系统信息
const osInfo = await si.osInfo();
console.log('操作系统信息:');
console.log(`- 平台: ${osInfo.platform}`);
console.log(`- 发行版: ${osInfo.distro}`);
console.log(`- 版本: ${osInfo.release}`);
console.log('');
// 磁盘信息
const disks = await si.diskLayout();
console.log('磁盘信息:');
disks.forEach((disk, i) => {
console.log(`- 磁盘 ${i}:`);
console.log(` - 类型: ${disk.type}`);
console.log(` - 名称: ${disk.name}`);
console.log(` - 接口类型: ${disk.interfaceType}`);
console.log(` - 大小: ${(disk.size / 1024 / 1024 / 1024).toFixed(2)}GB`);
console.log('');
});
// 网络接口信息
const networkInterfaces = await si.networkInterfaces();
console.log('网络接口信息:');
networkInterfaces.forEach((iface, i) => {
console.log(`- 接口 ${i}:`);
console.log(` - 名称: ${iface.iface}`);
console.log(` - 型号: ${iface.model}`);
console.log(` - MAC地址: ${iface.mac}`);
console.log(` - IPv4地址: ${iface.ip4}`);
console.log(` - IPv6地址: ${iface.ip6}`);
console.log('');
});
console.log('');
console.log('-----电脑信息获取完毕!!');
} catch (error) {
console.error(`获取系统信息出错: ${error}`);
}
}
export {
displaySystemInfo
}