Python用WMI模块获取windowns系统信息
安装vmi
https://pypi.org/project/WMI/#history
脚本如下:
- #!/usr/bin/env python
- #coding:utf-
- 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)/)
- def cpu_use():
- #5s取一次CPU的使用率
- c = wmi.WMI()
- while True:
- for cpu in c.Win32_Processor():
- timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
- print '%s | Utilization: %s: %d %%' % (timestamp, cpu.DeviceID, cpu.LoadPercentage)
- time.sleep()
- 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=):
- 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=):
- print "MAC: %s" % interface.MACAddress
- for ip_address in interface.IPAddress:
- print "ip_add: %s" % ip_address
- #获取自启动程序的位置
- for s in c.Win32_StartupCommand ():
- print "[%s] %s <%s>" % (s.Location.encode("UTF8"), s.Caption.encode("UTF8"), s.Command.encode("UTF8"))
- #获取当前运行的进程
- for process in c.Win32_Process ():
- print process.ProcessId, process.Name
- def main():
- sys_version()
- #cpu_mem()
- #disk()
- #network()
- #cpu_use()
- if __name__ == '__main__':
- main()
- print platform.system()
- print platform.release()
- print platform.version()
- print platform.platform()
- print platform.machine()
执行结果:
- Version:Microsoft Windows 家庭中文版 Vernum:
- 位
- Windows
- 10.0.
- Windows--10.0.
- AMD64
参考:http://blog.51cto.com/wangwei007/1158075
Python用WMI模块获取windowns系统信息的更多相关文章
- python使用wmi模块获取windows下的系统信息监控系统-乾颐堂
Python用WMI模块获取Windows系统的硬件信息:硬盘分区.使用情况,内存大小,CPU型号,当前运行的进程,自启动程序及位置,系统的版本等信息. 本文实例讲述了python使用wmi模块获取w ...
- Python使用WMI模块获取Windows系统的硬件信息,并使用pyinstaller库编译打包成exe的可执行文件
由于公司现阶段大多数应用软件都是基于Windows系统开发和部署,很多软件安装部署都是在windows server 2012.windows server 2008之类的服务器上,部门同事每次测试一 ...
- python用WMI模块获取系统命名空间
可以和winmgmts的查询页面对应 from win32com.client import GetObject import pywintypes result=[] def enum_namesp ...
- python封装configparser模块获取conf.ini值(优化版)
昨天晚上封装了configparser模块,是根据keyname获取的value.python封装configparser模块获取conf.ini值 我原本是想通过config.ini文件中的sect ...
- python wmi模块 获取windows内部信息
WMI (Windows Management Instrumentation) 模块可用于获取 Windows 内部信息,在使用Python获取Windows系统上的相关的信息可以使用WMI接口来获 ...
- python之psutil模块(获取系统性能数据)
psutil模块 1.介绍 psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等) ...
- python通过getopt模块获取执行命令参数
python脚本和shell脚本一样可以获取命令行的参数,根据不同的参数,执行不同的逻辑处理. 通常我们可以通过getopt模块获得不同的执行命令和参数. 下面我通过新建一个test.py的脚本解释下 ...
- python封装configparser模块获取conf.ini值
configparser模块是python自带的从文件中获取固定格式参数的模块,因为是python只带的,大家用的应该很多,我觉得这个参数模块比较灵活,添加参数.修改参数.读取参数等都有对应的参数供用 ...
- python使用platform模块获取系统环境并去除换行符
近来在porting一个网站,企图拿到这个网站的数据来做分析.为了支持多系统环境的正常运行.需要知道当前系统环境的是什么OS? 1.python内置platform库.可以很方便得到当前系统环境时什么 ...
随机推荐
- 从零开始のcocos2dx生活(八)ParticleSystemQuad
https://learnopengl-cn.github.io/01%20Getting%20started/04%20Hello%20Triangle/#_1 写的真的非常好-最近没时间拜读,只看 ...
- CSRF绕过后端Referer校验
CSRF绕过后端Referer校验分正常情况和不正常的情况,我们这里主要讨论开发在写校验referer程序时,不正常的情况下怎么进行绕过. 正常情况 正常的情况指服务器端校验Referer的代码没毛病 ...
- 小小知识点(三十九) 正交频分复用OFDM的基本原理及实现
引言 符号间干扰(ISI)是无线传输系统设计中需要考虑的因素,采用什么样的处理方法取决于数据传输速率或等效传输带宽来决定 (1)若数据速率低且与信道最大延迟相比符号持续时间较长,那么就可能无需任何均衡 ...
- linux入门系列3--常见的linux远程登陆管理工具
服务器一般是云服务器或者放置在机房,我们日常工作中通过远程连接工具连接到服务器进行操作,这类工具很多(如SecureCRT.XShell.Putty.FinallShell.TeamViewer以及w ...
- java数据结构之常用排序算法
冒泡排序 private void maopao(int arr[]) { for (int i = 0; i < arr.length; i++) { for (int j = 0; j &l ...
- 《大厂面试》京东+百度一面,不小心都拿了Offer
你知道的越多,你不知道的越多 点赞再看,养成习惯 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试点思维导图,也整理了很多我的文档,欢迎Star和 ...
- Java类成员之属性
属性含义:对应类中的成员变量. 语法格式:修饰符 数据类型 属性名 = 初始化值; 1.修饰符常用的有权限修饰符(private.default.protected.public) 以及其他修饰符(s ...
- 从源码角度来看BeanFactory和ApplicationContext的关系
大家好,我是小黑,这是年前的最后一篇推文,提前祝大家新年快乐~~ 这次我们从源码角度来聊聊BeanFactory和ApplicationContext的关系,讲一些网上文章不曾提到的点. 官方描述 先 ...
- python 矩阵向右旋转90°(分行输入输出)
输入格式 第一行输入两个整数n,m,用空格隔开. 接下来n行,每行输入m个整数,表示输入矩阵.矩阵元素都是int范围内的整数. 输出格式 输出m行,每行n个空格隔开的整数,表示旋转以后的矩阵.注意:每 ...
- 【开源】后台权限管理系统升级到aspnetcore3.1
*:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...