python使用wmi模块获取windows下的系统信息监控系统

python用wmi模块获取windows系统的硬件信息:硬盘分区、使用情况,内存大小,cpu型号,当前运行的进程,自启动程序及位置,系统的版本等信息。

本文实例讲述了python使用wmi模块获取windows下的系统信息 监控系统

#!/usr/bin/env python
# -*- coding: utf- -*-
#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.win_operatingsystem():
print “version:%s” % sys.caption.encode(“utf”),”vernum:%s” % sys.buildnumber
print sys.osarchitecture.encode(“utf”)#系统是位还是位的
print sys.numberofprocesses #当前系统运行的进程总数
def cpu_mem():
c = wmi.wmi ()
#cpu类型和内存
for processor in c.win_processor():
#print “processor id: %s” % processor.deviceid
print “process name: %s” % processor.name.strip()
for memory in c.win_physicalmemory():
print “memory capacity: %.fmb” %(int(memory.capacity)/)
def disk():
c = wmi.wmi ()
#获取硬盘分区
for physical_disk in c.win_diskdrive ():
for partition in physical_disk.associators (“win_diskdrivetodiskpartition”):
for logical_disk in partition.associators (“win_logicaldisktopartition”):
print physical_disk.caption.encode(“utf”), partition.caption.encode(“utf”), logical_disk.caption
#获取硬盘使用百分情况
for disk in c.win_logicaldisk (drivetype=):
print disk.caption, “%.f%% free” % (. * long (disk.freespace) / long (disk.size))
def network():
c = wmi.wmi ()
#获取mac和ip地址
for interface in c.win_networkadapterconfiguration (ipenabled=):
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使用wmi模块获取windows下的系统信息 监控系统的相关知识,希望对大家有所帮助。

Posted in 未分类

发表评论