Python通过WMI模块获取windows系统信息,对系统参数进行监控。
1 #!/usr/bin/env python 2 # -*- Coding: utf-8 -*- 3 #http://www.cnblogs.com/liu-ke/ 4 import wmi 5 import os 6 import sys 7 import platform 8 import time 9 10 def sys_version(): 11 c = wmi.WMI () 12 #获取 *** 作系统版本 13 for sys in c.Win32_OperatingSystem(): 14 print "Version:%s" % sys.Caption.encode("UTF8"),"Vernum:%s" % sys.BuildNumber 15 print sys.OSArchitecture.encode("UTF8")#系统是32位还是64位的 16 print sys.NumberOfProcesses #当前系统运行的进程总数17 18 def cpu_mem(): 19 c = wmi.WMI () 20 #cpu类型和内存 21 for processor in c.Win32_Processor(): 22 #print "Processor ID: %s" % processor.deviceid 23 print "Process name: %s" % processor.name.strip() 24 for Memory in c.Win32_PhysicalMemory(): 25 print "Memory Capacity: %.fMB" %(int(Memory.Capacity)/1048576) 26 27 28 29 def disk(): 30 c = wmi.WMI () 31 #获取硬盘分区 32 for physical_disk in c.Win32_diskDrive (): 33 for partition in physical_disk.associators ("Win32_diskDrivetodiskPartition"): 34 for logical_disk in partition.associators ("Win32_Logicaldisktopartition"): 35 print physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8"), logical_disk.Caption 36 37 #获取硬盘使用百分情况 38 for disk in c.Win32_Logicaldisk (DriveType=3): 39 print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size)) 40 41 def network(): 42 c = wmi.WMI () 43 #获取MAC和IP地址 44 for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): 45 print "MAC: %s" % interface.MACAddress 46 for ip_address in interface.IPAddress: 47 print "ip_add: %s" % ip_address 48 print 49 50 51 def main(): 52 sys_version() 53 cpu_mem() 54 #disk() 55 #network() 56 57 if __name__ == '__main__': 58 main() 59 print platform.system() 60 print platform.release() 61 print platform.version() 62 print platform.platform() 63 print platform.machine()
总结
以上是内存溢出为你收集整理的Python WMI获取Windows系统信息 监控系统全部内容,希望文章能够帮你解决Python WMI获取Windows系统信息 监控系统所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)