Python获取硬盘、CPU、主板、网卡、内存的硬件信息
本帖最后由 纸条 于 2023-2-7 10:55 编辑### 上个月修完电脑,发现系统由激活变成未激活,没留意。打开视频发现硬件码变了,联想到零件可能被商家换掉了,网上抄个代码,自己改一下获取电脑的硬件信息。
```
import wmi
WMI = wmi.WMI()
# 硬盘信息
for diskinfo in WMI.Win32_DiskDrive():
if '虚拟' not in diskinfo.Caption:
Manufacturer = diskinfo.Manufacturer
SerialNumber = diskinfo.SerialNumber
Size = diskinfo.Size
print(f'制造商:{Manufacturer}\n序列号:{SerialNumber}\n硬盘大小:{Size}')
# CPU信息
for cpuinfo in WMI.Win32_Processor():
Name = cpuinfo.Name
Manufacturer = cpuinfo.Manufacturer
ProcessorId = cpuinfo.ProcessorId
NumberOfCores = cpuinfo.NumberOfCores
SerialNumber = cpuinfo.SerialNumber
print(f'名称:{Name}\n制造商:{Manufacturer}\nID号:{ProcessorId}\n序列号:{SerialNumber}\n核心数:{NumberOfCores}')
# 主板信息
for boardinfo in WMI.Win32_BaseBoard():
Manufacturer = boardinfo.Manufacturer
Product = boardinfo.Product
SerialNumber = boardinfo.SerialNumber
print(f'制造商:{Manufacturer}\n产品号:{Product}\n序列号:{SerialNumber}')
# 网卡信息
for NetworkAdapter in WMI.Win32_NetworkAdapter():
MACAddress = NetworkAdapter.MACAddress
if MACAddress:
Name = NetworkAdapter.Name
Manufacturer = NetworkAdapter.Manufacturer
print(f'名称:{Name}\n制造商:{Manufacturer}\nMAC地址:{MACAddress}')
# bios信息
for biosinfo in WMI.Win32_BIOS():
Name = biosinfo.Name
Manufacturer = biosinfo.Manufacturer
SerialNumber = biosinfo.SerialNumber
print(f'名称:{Name}\n制造商:{Manufacturer}\n序列号:{SerialNumber}')
# 内存信息
for memoryinfo in WMI.Win32_PhysicalMemory():
Manufacturer = memoryinfo.Manufacturer
PartNumber = memoryinfo.PartNumber
SerialNumber = memoryinfo.SerialNumber
Capacity = memoryinfo.Capacity
print(f'制造商:{Manufacturer}\n部件号:{PartNumber}\n序列号:{SerialNumber}\n内存大小:{Capacity}')
``` 试用了一下楼主分享的代码,对于俺的电脑来说,信息很准确。收藏了,感谢楼主分享。 试试去{:1_893:}谢谢 学到了,感谢分享 感谢分享 所以你查看了之后,真的被换了吗? 试试看,谢谢大侠分享。 感谢楼主分享 这个挺实用的~