Python WMI获取Windows系统信息 监控系统
2015-10-26 14:58
796 查看
#!/usr/bin/env python # -*- coding: utf-8 -*- #http://www.cnblogs.com/liu-ke/ import wmi import os import sys import platform import time def sys_version(): c = wmi.WMI () #获取操作系统版本 for sys in c.Win32_OperatingSystem(): print "Version:%s" % sys.Caption.encode("UTF8"),"Vernum:%s" % sys.BuildNumber print sys.OSArchitecture.encode("UTF8")#系统是32位还是64位的 print sys.NumberOfProcesses #当前系统运行的进程总数 def cpu_mem(): c = wmi.WMI () #CPU类型和内存 for processor in c.Win32_Processor(): #print "Processor ID: %s" % processor.DeviceID print "Process Name: %s" % processor.Name.strip() for Memory in c.Win32_PhysicalMemory(): print "Memory Capacity: %.fMB" %(int(Memory.Capacity)/1048576) def disk(): c = wmi.WMI () #获取硬盘分区 for physical_disk in c.Win32_DiskDrive (): for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"): for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"): print physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8"), logical_disk.Caption #获取硬盘使用百分情况 for disk in c.Win32_LogicalDisk (DriveType=3): print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size)) def network(): c = wmi.WMI () #获取MAC和IP地址 for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): print "MAC: %s" % interface.MACAddress for ip_address in interface.IPAddress: print "ip_add: %s" % ip_address print def main(): sys_version() cpu_mem() #disk() #network() if __name__ == '__main__': main() print platform.system() print platform.release() print platform.version() print platform.platform() print platform.machine()
相关文章推荐
- Python学习资源
- python 包管理
- python Synchronization between processes
- Python二维码生成库qrcode安装和使用示例
- Python点点滴滴积累---getopt使用(详解)
- python之报错的解决(持续总结)
- Python基础(十)正则表达式
- Python 深入理解yield
- tornado 学习笔记2 Python web主流框架
- tkinter 学习笔记
- python的一些日期处理方法(工具)
- python集合
- python培训Day1 随笔
- 快速入门:十分钟学会Python(转)
- Python学习笔记5
- Python入门教程 超详细1小时学会Python(转)
- python中文显示报错
- Python Cookie操作实战---requests&selenium&urllib2
- Ubuntu下一个python的BeautifulSoup和rsa安装方法---信息检索project2部分:微博爬行要求python包裹
- 笨办法学python的笔记之八(ex42 class类)