python使用wmi模块获取windows下的系统信息 监控系统
Python用WMI模块获取Windows系统的硬件信息:硬盘分区、使用情况,内存大小,CPU型号,当前运行的进程,自启动程序及位置,系统的版本等信息。
本文实例讲述了python使用wmi模块获取windows下的系统信息监控系统
#!/usr/bin/envpython
#-*-coding:utf--*-
#http://www.cnblogs.com/liu-ke/
importwmi
importos
importsys
importplatform
importtime
defsys_version():
c=wmi.WMI()
#获取操作系统版本
forsysinc.Win_OperatingSystem():
print"Version:%s"%sys.Caption.encode("UTF"),"Vernum:%s"%sys.BuildNumber
printsys.OSArchitecture.encode("UTF")#系统是位还是位的
printsys.NumberOfProcesses#当前系统运行的进程总数
defcpu_mem():
c=wmi.WMI()
#CPU类型和内存
forprocessorinc.Win_Processor():
#print"ProcessorID:%s"%processor.DeviceID
print"ProcessName:%s"%processor.Name.strip()
forMemoryinc.Win_PhysicalMemory():
print"MemoryCapacity:%.fMB"%(int(Memory.Capacity)/)
defdisk():
c=wmi.WMI()
#获取硬盘分区
forphysical_diskinc.Win_DiskDrive():
forpartitioninphysical_disk.associators("Win_DiskDriveToDiskPartition"):
forlogical_diskinpartition.associators("Win_LogicalDiskToPartition"):
printphysical_disk.Caption.encode("UTF"),partition.Caption.encode("UTF"),logical_disk.Caption
#获取硬盘使用百分情况
fordiskinc.Win_LogicalDisk(DriveType=):
printdisk.Caption,"%.f%%free"%(.*long(disk.FreeSpace)/long(disk.Size))
defnetwork():
c=wmi.WMI()
#获取MAC和IP地址
forinterfaceinc.Win_NetworkAdapterConfiguration(IPEnabled=):
print"MAC:%s"%interface.MACAddress
forip_addressininterface.IPAddress:
print"ip_add:%s"%ip_address
print
defmain():
sys_version()
cpu_mem()
#disk()
#network()
if__name__=='__main__':
main()
printplatform.system()
printplatform.release()
printplatform.version()
printplatform.platform()
printplatform.machine()
以上内容是关于python使用wmi模块获取windows下的系统信息监控系统的相关知识,希望对大家有所帮助。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短