Python WMI获取Windows系统信息
2018-06-18 00:23:59来源:未知 阅读 ()
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 def cpu_use(): 28 #5s取一次CPU的使用率 29 c = wmi.WMI() 30 while True: 31 for cpu in c.Win32_Processor(): 32 timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime()) 33 print '%s | Utilization: %s: %d %%' % (timestamp, cpu.DeviceID, cpu.LoadPercentage) 34 time.sleep(5) 35 36 def disk(): 37 c = wmi.WMI () 38 #获取硬盘分区 39 for physical_disk in c.Win32_DiskDrive (): 40 for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"): 41 for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"): 42 print physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8"), logical_disk.Caption 43 44 #获取硬盘使用百分情况 45 for disk in c.Win32_LogicalDisk (DriveType=3): 46 print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size)) 47 48 def network(): 49 c = wmi.WMI () 50 #获取MAC和IP地址 51 for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): 52 print "MAC: %s" % interface.MACAddress 53 for ip_address in interface.IPAddress: 54 print "ip_add: %s" % ip_address 55 print 56 57 #获取自启动程序的位置 58 for s in c.Win32_StartupCommand (): 59 print "[%s] %s <%s>" % (s.Location.encode("UTF8"), s.Caption.encode("UTF8"), s.Command.encode("UTF8")) 60 61 62 #获取当前运行的进程 63 for process in c.Win32_Process (): 64 print process.ProcessId, process.Name 65 66 def main(): 67 sys_version() 68 cpu_mem() 69 #disk() 70 #network() 71 #cpu_use() 72 73 if __name__ == '__main__': 74 main() 75 print platform.system() 76 print platform.release() 77 print platform.version() 78 print platform.platform() 79 print platform.machine()
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:python:递归函数
下一篇:单例模式
- python3基础之“术语表(2)” 2019-08-13
- python3 之 字符串编码小结(Unicode、utf-8、gbk、gb2312等 2019-08-13
- Python3安装impala 2019-08-13
- 小白如何入门 Python 爬虫? 2019-08-13
- python_字符串方法 2019-08-13
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash