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
print #获取自启动程序的位置
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库.可以很方便得到当前系统环境时什么 ...
随机推荐
- 小白学 Python 爬虫(31):自己构建一个简单的代理池
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- MySQL中文乱码 - window环境
MySQL中文乱码 window环境 Linux环境请参考这篇文章:[https://www.cnblogs.com/hankleo/p/9695842.html]: 查看及修改字符集sql --查看 ...
- 手写vue observe数据劫持
实现代码: class Vue { constructor(options) { //缓存参数 this.$options = options; //需要监听的数据 this.$data = opti ...
- Hexo + Serverless Framework,简单三步搭建你的个人博客
很多人都想拥有自己的个人博客,还得看起来漂亮.酷酷的.尤其对开发者来说,不仅可以分享技术(装)心得(逼),面试的时候还能成为加分.这里介绍两款好用的神器,不用忙前(前端)忙后(后端),简单3min即可 ...
- Theia APIs——通过JSON-RPC进行通信
上一篇:Theia APIs——事件 通过JSON-PRC进行通信 在本节中,我将讲解如何创建后端服务并通过JSON-PRC来连接它. 我将使用debug logging system作为例子来进行讲 ...
- .Net Core - AgileHttp
2020年新年将至,先预祝.Net Core越来越好. 做了这么多年一线开发,经常跟Http打交道.比如调用三方的Webservice,比如集成微信支付的时候服务端发起Prepay支付.特别是现在分布 ...
- Java之IO流用法总结
Java的IO流概述:1.I/O是Input/Output的缩写,I/O技术是非常实用的技术,用于处理设备之间的数据传输.如读/写文件,网络通讯等.2.Java程序中,对于数据的输入/输出操作以“流( ...
- 一个DNS数据包的惊险之旅
踏上旅程 “小子,快去查一下www.paypal.com的IP地址,我急用,晚了我弄你!”,暴躁老哥一把关上了门,留我一个DNS数据包在冷冰冰的房间. 过了一会儿,一位大叔打开了门,带着我来到了一座叫 ...
- cogs 3008. 朋友圈
3008. 朋友圈 ★★ 输入文件:friendscircle.in 输出文件:friendscircle.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] NO ...
- 2019 ICCV、CVPR、ICLR之视频预测读书笔记
2019 ICCV.CVPR.ICLR之视频预测读书笔记 作者 | 文永亮 学校 | 哈尔滨工业大学(深圳) 研究方向 | 视频预测.时空序列预测 ICCV 2019 CVP github地址:htt ...