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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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(): 
  = 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(): 
  = 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(): 
  = 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(): 
  = 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下的系统信息 监控系统的相关知识,希望对大家有所帮助。

www.qytang.com/
http://www.qytang.com/cn/list/29/
http://www.qytang.com/cn/list/28/446.htm
http://www.qytang.com/cn/list/28/445.htm
http://www.qytang.com/cn/list/28/444.htm
http://www.qytang.com/cn/list/28/442.htm
http://www.qytang.com/cn/list/28/440.htm
http://www.qytang.com/cn/list/28/437.htm
http://www.qytang.com/cn/list/28/435.htm
http://www.qytang.com/cn/list/28/434.htm
http://www.qytang.com/cn/list/28/433.htm
http://www.qytang.com/cn/list/28/431.htm
http://www.qytang.com/cn/list/28/328.htm
http://www.qytang.com/cn/list/28/326.htm
http://www.qytang.com/cn/list/28/429.htm

python使用wmi模块获取windows下的系统信息监控系统-乾颐堂的更多相关文章

  1. Python使用WMI模块获取Windows系统的硬件信息,并使用pyinstaller库编译打包成exe的可执行文件

    由于公司现阶段大多数应用软件都是基于Windows系统开发和部署,很多软件安装部署都是在windows server 2012.windows server 2008之类的服务器上,部门同事每次测试一 ...

  2. python wmi模块 获取windows内部信息

    WMI (Windows Management Instrumentation) 模块可用于获取 Windows 内部信息,在使用Python获取Windows系统上的相关的信息可以使用WMI接口来获 ...

  3. python中os模块在windows下的使用

    今天学习了一下Python的os模块,主要是针对文件夹和文件路径的一系列操作. 与Python内置函数相比这里这里的函数功能更多样化,功能也更强大.但是学习过程中我发现很多函数都是只适用于unix系统 ...

  4. Python用WMI模块获取windowns系统信息

    安装vmi https://pypi.org/project/WMI/#history 脚本如下: #!/usr/bin/env python #coding:utf- import wmi impo ...

  5. python用WMI模块获取系统命名空间

    可以和winmgmts的查询页面对应 from win32com.client import GetObject import pywintypes result=[] def enum_namesp ...

  6. Python获取服务器的厂商和型号信息-乾颐堂

    Python获取服务器的厂商和型号信息,在RHEHL6下,需要系统预装python-dmidecode这个包(貌似默认就已经装过了) 脚本内容如下 [root@linuxidc tmp]# cat t ...

  7. HTTP 499状态码 nginx下499错误详解-乾颐堂

    日志记录中HTTP状态码出现499错误有多种情况,我遇到的一种情况是nginx反代到一个永远打不开的后端,就这样了,日志状态记录是499.发送字节数是0. 老是有用户反映网站系统时好时坏,因为线上的产 ...

  8. Python的requests、greenlet和gevent模块在windows下安装

    一.requests模块在windows下安装 Linux系统下requests的安装方法在http://docs.python-requests.org/en/latest/user/install ...

  9. python封装configparser模块获取conf.ini值(优化版)

    昨天晚上封装了configparser模块,是根据keyname获取的value.python封装configparser模块获取conf.ini值 我原本是想通过config.ini文件中的sect ...

随机推荐

  1. [Python] 分段线性插值

    利用线性函数做插值 每一段的线性函数: #Program 0.6 Linear Interploation import numpy as np import matplotlib.pyplot as ...

  2. Petapoco 查询 语法

    查询语句 Sql sql = Sql.Builder; sql.Select("spb_MailAddress.*") .From("spb_MailAddress&qu ...

  3. C++官方文档-运算符重载

    #include <iostream> using namespace std; class CVector { public: int x, y; CVector() : x(), y( ...

  4. uva-331-枚举-交换的方案数

    题意:冒泡排序,最小交换数的前提下有多少用方案把数组变成从小到大的顺序, 注意: 3 2 1 3的下表是1  2的是2 1的是3  交换 3 2,那么第一个交换数是1 最小交换数=逆序数的和 那么,只 ...

  5. as3的全屏功能的实现主要是舞台stage的displayState属性

    StageDisplayState.NORMAL                                               正常 StageDisplayState.FULL_SCR ...

  6. 常用HTTP状态码

    1.常用状态码介绍 在http响应协议中,我们通过HttpWatch抓包抓取到响应信息.其中响应首行中就包含一个状态码.状态码由三位数字组成,表示请求是否被理解或者被满足.HTTP响应状态码的第一个数 ...

  7. NUMA体系结构介绍

    为什么会有NUMA? 在NUMA架构出现前,CPU欢快的朝着频率越来越高的方向发展.受到物理极限的挑战,又转为核数越来越多的方向发展.如果每个core的工作性质都是share-nothing(类似于m ...

  8. 基于Sentinel的Redis3.2高可用方案

    默认情况下,Redis node和sentinel的protected-mode都是yes,在搭建集群时,若想从远程连接redis集群,需要将redis.conf和sentinel.conf的prot ...

  9. java包 命名规范 [转]

    Java的包名都有小写单词组成,类名首字母大写:包的路径符合所开发的 系统模块的 定义,比如生产对生产,物资对物资,基础类对基础类.以便看了包名就明白是哪个模块,从而直接到对应包里找相应的实现. 由于 ...

  10. ElementTree 解析xml(minidom解析xml大文件时,MemoryError)

    在使用minido解析xml文件时,因为文件过大,结果报错MemoryError.查询后得知是因为minidom在解析时是将所有文件放到内存里的,很占用内存,所以要考虑换一种方法来处理xml文件.   ...