一、获取CPU信息
def get_cpu_info(self):
tmpdict = {}
tmpdict["CpuCores"] = 0
c = wmi.WMI()
# print c.Win32_Processor().['ProcessorId']
# print c.Win32_DiskDrive()
for cpu in c.Win32_Processor():
# print cpu
print("cpu id:", cpu.ProcessorId.strip())
tmpdict["CpuType"] = cpu.Name
try:
tmpdict["CpuCores"] = cpu.NumberOfCores
except:
tmpdict["CpuCores"] += 1
tmpdict["CpuClock"] = cpu.MaxClockSpeed
return tmpdict
二、获取CPU使用负载
def read_cpu_usage(self):
c = wmi.WMI()
for cpu in c.Win32_Processor():
return cpu.LoadPercentage
三、获取CPU/磁盘/BIOS序列号
def get_disk_info(self):
tmplist = []
encrypt_str = ""
c = wmi.WMI()
for cpu in c.Win32_Processor():
# cpu 序列号
encrypt_str = encrypt_str + cpu.ProcessorId.strip()
print("cpu id:", cpu.ProcessorId.strip())
for physical_disk in c.Win32_DiskDrive():
encrypt_str = encrypt_str + physical_disk.SerialNumber.strip()
# 硬盘序列号
print('disk id:', physical_disk.SerialNumber.strip())
tmpdict = {}
tmpdict["Caption"] = physical_disk.Caption
tmpdict["Size"] = int(physical_disk.Size) / 1000 / 1000 / 1000
tmplist.append(tmpdict)
for board_id in c.Win32_BaseBoard():
# 主板序列号
encrypt_str = encrypt_str + board_id.SerialNumber.strip()
print("main board id:", board_id.SerialNumber.strip())
# for mac in c.Win32_NetworkAdapter():
# mac 地址(包括虚拟机的)
# print "mac addr:", mac.MACAddress:
for bios_id in c.Win32_BIOS():
# bios 序列号
encrypt_str = encrypt_str + bios_id.SerialNumber.strip()
print("bios number:", bios_id.SerialNumber.strip())
print("encrypt_str:", encrypt_str)
return encrypt_str
四、获取获取磁盘序列号信息,返回值类似:185224465301
def get_HardDiskNumber(self):
"""
获取磁盘序列号信息,返回值类似:185224465301
:return:
"""
print('\n------ get HardDiskNumber ------')
import wmi
c = wmi.WMI()
for physical_disk in c.Win32_DiskDrive():
physical_disk_sn=physical_disk.SerialNumber
print('get_HardDiskNumber=',physical_disk_sn)
return physical_disk_sn