Python 通过wmi获取Window服务器硬件信息
通过订阅财经新闻短信或邮件获取简明信息。 #生活技巧# #个人理财技巧# #金融资讯获取#
通过pip install wmi安装wmi
查看cpu序列号:
wmic cpu get processorid
查看主板序列号:
wmic baseboard get serialnumber
查看网卡信息:
wmic nicconfig get macaddress
通过Python获取
#!/usr/bin/env python # -*- coding: utf-8 -*- import os, sys 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 # BIOS def printBIOS(): bioss = [] for bios_id in c.Win32_BIOS(): tmpmsg = {} tmpmsg['BiosCharacteristics'] = bios_id.BiosCharacteristics # BIOS特征码 tmpmsg['version'] = bios_id.Version # BIOS版本 tmpmsg['Manufacturer'] = bios_id.Manufacturer.strip() # BIOS固件生产厂家 tmpmsg['ReleaseDate'] = bios_id.ReleaseDate # BIOS释放日期 tmpmsg['SMBIOSBIOSVersion'] = bios_id.SMBIOSBIOSVersion # 系统管理规范版本 bioss.append(tmpmsg) print (bioss) return bioss # 硬盘 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() printBIOS() printDisk() printPhysicalMemory() printMacAddress() printBattery() if __name__ == '__main__': main()
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128网址:Python 通过wmi获取Window服务器硬件信息 https://www.yuejiaxmz.com/news/view/278973
相关内容
通过API接口,轻松获取生活服务资信我获取信息的方法
Python 神器:wxauto 库——解锁微信自动化的无限可能
黑客如何通过网络获取到你的个人信息?
用Python发送邮件,需要这样三步
python毕设家政服务网上预约与管理系统2fkxz程序+论文
「福州速洁保洁服务部招聘信息」
便民信息汇总:快速获取生活中的各类便利信息!
Python自动化任务
信息公开专栏