安装wmi 和 win32com 这两个必要的库
pip install wmi
pip intsall win32com
(ps :pip 在 win+r cmd 命令里面直接输入 一般py3 以后都可以直接用 py2 可百度python pip
import os, sys,win32com
import wmi #引入需要的包
c = wmi.WMI() #创建对象
#输出处理器信息
def printCPU():
tmpdict = {} #创建字典
tmpdict["CpuCores"] = 0
for cpu in c.Win32_Processor():
tmpdict["cpuid"] = cpu.ProcessorId.strip()
tmpdict["CpuType"] = cpu.Name
tmpdict['systemName'] = cpu.SystemName
try:
tmpdict["CpuCores"] = cpu.NumberOfCores
except:
tmpdict["CpuCores"] += 1
tmpdict["CpuClock"] = cpu.MaxClockSpeed
tmpdict['DataWidth'] = cpu.DataWidth
print (tmpdict)
return tmpdict
#输出主板信息
def printMain_board():
boards = []
# print len(c.Win32_BaseBoard()):
for board_id in c.Win32_BaseBoard():
tmpmsg = {}
tmpmsg['UUID'] = board_id.qualifiers['UUID'][1:-1] #主板UUID,有的主板这部分信息取到为空值,ffffff-ffffff这样的
tmpmsg['SerialNumber'] = board_id.SerialNumber #主板序列号
tmpmsg['Manufacturer'] = board_id.Manufacturer #主板生产品牌厂家
tmpmsg['Product'] = board_id.Product #主板型号
boards.append(tmpmsg)
print (boards)
return boards
#输出硬盘信息
def printDisk():
disks = []
for disk in c.Win32_DiskDrive():
# print disk.__dict__
tmpmsg = {}
tmpmsg['SerialNumber'] = disk.SerialNumber.strip()
tmpmsg['DeviceID'] = disk.DeviceID
tmpmsg['Caption'] = disk.Caption
tmpmsg['Size'] = disk.Size
tmpmsg['UUID'] = disk.qualifiers['UUID'][1:-1]
disks.append(tmpmsg)
for d in disks:
print (d)
return disks
#输出内存信息
def printPhysicalMemory():
memorys = []
for mem in c.Win32_PhysicalMemory():
tmpmsg = {}
tmpmsg['UUID'] = mem.qualifiers['UUID'][1:-1]
tmpmsg['BankLabel'] = mem.BankLabel
tmpmsg['SerialNumber'] = mem.SerialNumber.strip()
tmpmsg['ConfiguredClockSpeed'] = mem.ConfiguredClockSpeed
tmpmsg['Capacity'] = mem.Capacity
tmpmsg['ConfiguredVoltage'] = mem.ConfiguredVoltage
memorys.append(tmpmsg)
for m in memorys:
print (m)
return memorys
#电池信息,只有笔记本才会有电池选项
def printBattery():
isBatterys = False
for b in c.Win32_Battery():
isBatterys = True
return isBatterys
#网卡mac地址:
def printMacAddress():
macs = []
for n in c.Win32_NetworkAdapter():
mactmp = n.MACAddress
if mactmp and len(mactmp.strip()) > 5:
tmpmsg = {}
tmpmsg['MACAddress'] = n.MACAddress
tmpmsg['Name'] = n.Name
tmpmsg['DeviceID'] = n.DeviceID
tmpmsg['AdapterType'] = n.AdapterType
tmpmsg['Speed'] = n.Speed
macs.append(tmpmsg)
print (macs)
return macs
def main():
#主函数调用
printCPU()
printMain_board()
printDisk()
printPhysicalMemory()
printMacAddress()
print (printBattery())
if __name__ == '__main__':
main()#运行
最后运行一下
以up这台美帝良心想为例
「间谍过家家」约尔・福杰粘土人登场 立体手办▪
「街角魔族 2丁目」吉田优子手办开订 立体手办▪
「火影忍者 疾风传」旗木卡卡西·暗部版粘土人登场 立体手办▪
「佐佐木与宫野」宫野由美粘土人开订 立体手办▪
「盾之勇者成名录」第2季拉芙塔莉雅手办开订 立体手办▪
「咒术回战」两面宿傩Q版坐姿手办开订 立体手办▪
「DATE·A·BULLET」时崎狂三手办开订 立体手办▪
「狂赌之渊××」早乙女芽亚里粘土人开订 立体手办▪
「魔道祖师」魏无羨粘土人开订 立体手办▪
「新·奥特曼」奥特曼手办现已开订 立体手办▪
「间谍过家家」阿尼亚一番赏手办先行图公开 立体手办▪
「火影忍者 疾风传」漩涡鸣人粘土人开订 立体手办▪
「阴阳师」神堕八岐大蛇手办公开预售情报 立体手办▪
「罪恶装备 奋战」梅伊手办开订 立体手办▪
「我家猫女孩很可爱」黄豆粉手办开订 立体手办▪
「星之卡比」卡比30周年纪念粘土人开订 立体手办▪
「来自深渊 烈日的黄金乡」普鲁修卡粘土人开订 立体手办▪
「初音未来」生日会2021~兔子娘~手办公开 立体手办▪
eStream「咒术回战」两面宿傩手办开订 立体手办▪
「咒术回战」五条悟 虚式「茈」手办正式开订 立体手办▪
「排球少年!!」田中龙之介粘土人开订 立体手办▪