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


Posted in Python onOctober 27, 2015

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下的系统信息 监控系统的相关知识,希望对大家有所帮助。

Python 相关文章推荐
Python使用代理抓取网站图片(多线程)
Mar 14 Python
Python判断操作系统类型代码分享
Nov 22 Python
Python中编写ORM框架的入门指引
Apr 29 Python
深入解析Python编程中JSON模块的使用
Oct 15 Python
pandas中Timestamp类用法详解
Dec 11 Python
python多进程提取处理大量文本的关键词方法
Jun 05 Python
Django 模型类(models.py)的定义详解
Jul 19 Python
Python 类方法和实例方法(@classmethod),静态方法(@staticmethod)原理与用法分析
Sep 20 Python
python爬虫快速响应服务器的做法
Nov 24 Python
90行Python代码开发个人云盘应用
Apr 20 Python
Python基础之元编程知识总结
May 23 Python
Python中requests做接口测试的方法
May 30 Python
详解JavaScript编程中的window与window.screen对象
Oct 26 #Python
深入讲解Python中的迭代器和生成器
Oct 26 #Python
Windows下使Python2.x版本的解释器与3.x共存的方法
Oct 25 #Python
解析Python编程中的包结构
Oct 25 #Python
Python实现获取域名所用服务器的真实IP
Oct 25 #Python
Python制作爬虫采集小说
Oct 25 #Python
Python验证企业工商注册码
Oct 25 #Python
You might like
php使用curl访问https示例分享
2014/01/17 PHP
PHP @ at 记号的作用示例介绍
2014/10/10 PHP
php实现只保留mysql中最新1000条记录
2015/06/18 PHP
centos下file_put_contents()无法写入文件的原因及解决方法
2017/04/01 PHP
Laravel 解决composer相关操作提示php相关异常的问题
2019/10/23 PHP
各种效果的jquery ui(接口)介绍
2008/09/17 Javascript
基于jquery的商品展示放大镜
2010/08/07 Javascript
推荐40个简单的 jQuery 导航插件和教程(下篇)
2012/09/14 Javascript
js数组Array sort方法使用深入分析
2013/02/21 Javascript
Javascript模块化编程详解
2014/12/01 Javascript
CSS+JS实现点击文字弹出定时自动关闭DIV层菜单的方法
2015/05/12 Javascript
js实现仿Discuz文本框弹出层效果
2015/08/13 Javascript
ES6的新特性概览
2016/03/10 Javascript
node文件上传功能简易实现代码
2017/06/16 Javascript
jQuery实现腾讯信用界面(自制刻度尺)样式
2017/08/15 jQuery
js使用原型对象(prototype)需要注意的地方
2017/08/28 Javascript
JS实现左边列表移到到右边列表功能
2018/03/28 Javascript
vue中各种通信传值方式总结
2019/02/14 Javascript
Vue+Element UI+vue-quill-editor富文本编辑器及插入图片自定义
2019/08/20 Javascript
微信小程序开发数据缓存基础知识辨析及运用实例详解
2020/11/06 Javascript
pandas dataframe添加表格框线输出的方法
2019/02/08 Python
Python Selenium 之关闭窗口close与quit的方法
2019/02/13 Python
实例讲解Python中整数的最大值输出
2019/03/17 Python
python中tkinter的应用:修改字体的实例讲解
2019/07/17 Python
Python 列表去重去除空字符的例子
2019/07/20 Python
python中count函数简单用法
2020/01/05 Python
python爬虫开发之urllib模块详细使用方法与实例全解
2020/03/09 Python
python+appium+yaml移动端自动化测试框架实现详解
2020/11/24 Python
惠普美国官方商店:HP Official Store
2016/08/28 全球购物
华美博弈C/VC工程师笔试试题
2012/07/16 面试题
表彰先进的通报
2014/01/31 职场文书
淘宝店铺营销方案
2014/02/13 职场文书
自我管理的活动方案
2014/08/25 职场文书
总经理检讨书
2014/09/15 职场文书
2014年酒店服务员工作总结
2014/12/08 职场文书
工作表现证明
2015/06/15 职场文书