python写的用WMI检测windows系统信息的脚本
脚本如下:
#!/usr/bin/env python
#coding:utf- import wmi
import sys,time,platform def get_system_info(os):
"""
获取操作系统版本。
"""
print "Operating system:"
if os == "Windows":
c = wmi.WMI ()
for sys in c.Win32_OperatingSystem():
print '\t' + "Version :\t%s" % sys.Caption.encode("UTF-8")
print '\t' + "Vernum :\t%s" % sys.BuildNumber def get_memory_info(os):
"""
获取物理内存和虚拟内存。
"""
print "memory_info:"
if os == "Windows":
c = wmi.WMI ()
cs = c.Win32_ComputerSystem()
pfu = c.Win32_PageFileUsage()
MemTotal = int(cs[].TotalPhysicalMemory)//
print '\t' + "TotalPhysicalMemory :" + '\t' + str(MemTotal) + "M"
#tmpdict["MemFree"] = int(os[].FreePhysicalMemory)/
SwapTotal = int(pfu[].AllocatedBaseSize)
print '\t' + "SwapTotal :" + '\t' + str(SwapTotal) + "M"
#tmpdict["SwapFree"] = int(pfu[].AllocatedBaseSize - pfu[].CurrentUsage) def get_disk_info(os):
"""
获取物理磁盘信息。
"""
print "disk_info:"
if os == "Windows":
tmplist = []
c = wmi.WMI ()
for physical_disk in c.Win32_DiskDrive():
if physical_disk.Size:
print '\t' + str(physical_disk.Caption) + ' :\t' + str(long(physical_disk.Size)///) + "G" def get_cpu_info(os):
"""
获取CPU信息。
"""
print "cpu_info:"
if os == "Windows":
tmpdict = {}
tmpdict["CpuCores"] =
c = wmi.WMI ()
for cpu in c.Win32_Processor():
tmpdict["CpuType"] = cpu.Name
try:
tmpdict["CpuCores"] = cpu.NumberOfCores
except:
tmpdict["CpuCores"] +=
tmpdict["CpuClock"] = cpu.MaxClockSpeed
print '\t' + 'CpuType :\t' + str(tmpdict["CpuType"])
print '\t' + 'CpuCores :\t' + str(tmpdict["CpuCores"]) def get_network_info(os):
"""
获取网卡信息和当前TCP连接数。
"""
print "network_info:"
if os == "Windows":
tmplist = []
c = wmi.WMI ()
for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=):
tmpdict = {}
tmpdict["Description"] = interface.Description
tmpdict["IPAddress"] = interface.IPAddress[]
tmpdict["IPSubnet"] = interface.IPSubnet[]
tmpdict["MAC"] = interface.MACAddress
tmplist.append(tmpdict)
for i in tmplist:
print '\t' + i["Description"]
print '\t' + '\t' + "MAC :" + '\t' + i["MAC"]
print '\t' + '\t' + "IPAddress :" + '\t' + i["IPAddress"]
print '\t' + '\t' + "IPSubnet :" + '\t' + i["IPSubnet"]
for interfacePerfTCP in c.Win32_PerfRawData_Tcpip_TCPv4():
print '\t' + 'TCP Connect :\t' + str(interfacePerfTCP.ConnectionsEstablished) if __name__ == "__main__":
os = platform.system()
get_system_info(os)
get_memory_info(os)
get_disk_info(os)
get_cpu_info(os)
get_network_info(os)
执行结果:
Operating system:
Version : Microsoft Windows 家庭中文版
Vernum : memory_info:
TotalPhysicalMemory : 4011M
SwapTotal : 6656M disk_info:
TOSHIBA MQ01ABF050 : 465G
KINGSTON SA400S37120G : 111G cpu_info:
CpuType : Intel(R) Core(TM) i5-5257U CPU @ .70GHz
CpuCores : network_info:
Realtek RTL8723BE Wireless LAN .11n PCI-E NIC
MAC : :6D:C7:8D::8D
IPAddress : 192.168.0.103
IPSubnet : 255.255.255.0
TCP Connect :
参考:http://blog.51cto.com/wangwei007/1033760
python写的用WMI检测windows系统信息的脚本的更多相关文章
- Python WMI获取Windows系统信息 监控系统
#!/usr/bin/env python # -*- coding: utf-8 -*- #http://www.cnblogs.com/liu-ke/ import wmi import os i ...
- Python WMI获取Windows系统信息
#!/usr/bin/env python # -*- coding: utf-8 -*- #http://www.cnblogs.com/liu-ke/ import wmi import os i ...
- 用Python写了个下载快手视频的小脚本
最近又重新拾起了,对python的热情. 贴个地址: https://github.com/d1y/lovepack/blob/master/kuaishou.py 前戏说明 因为我近乎癫狂的喜欢一个 ...
- Python使用wmi获取Windows相关信息
在使用Python获取Windows系统上的相关的信息可以使用WMI接口来获取, 什么是wmi? WMI是一项核心的Windows管理技术,WMI作为一种规范和基础结构,通过它可以访问.配置.管理和监 ...
- 用python写windows服务
用python写windows服务(1) 以python2.5 为例需要软件 * python 2.5 * pywin32(与2.5 版本相匹配的) Service Control Ma ...
- 用PYTHON + PYWIN32 + WMI获取WINDOWS系统基本信息
网上原码,去了DECODE编码的问题. PyScripter这个PYTHON的IDE工具在WIN下表现不错哟. 感觉比SPYDER,ERIC,SUBLEME TEXT3之类的好用呀.. #!/usr/ ...
- 181102 Windows下安装kivy(用python写APP)
了解到Instgram,知乎等APP是用python写的.我也决定学习用python写APP.这里我们需要安装kivy. 环境:win7,python3.6 安装方式:DOS命令窗口 注意事项:目前不 ...
- 【Python】如何基于Python写一个TCP反向连接后门
首发安全客 如何基于Python写一个TCP反向连接后门 https://www.anquanke.com/post/id/92401 0x0 介绍 在Linux系统做未授权测试,我们须准备一个安全的 ...
- Python写各大聊天系统的屏蔽脏话功能原理
Python写各大聊天系统的屏蔽脏话功能原理 突然想到一个视频里面弹幕被和谐的一满屏的*号觉得很有趣,然后就想用python来试试写写看,结果还真玩出了点效果,思路是首先你得有一个脏话存放的仓库好到时 ...
随机推荐
- $UVA10559\ Blocks\ $区间$dp$
\(Des\) • 有一排数量为N的方块,每次可以把连续的相同颜色的区间消除,得到分数为 区间长度的平方,然后左右两边连在一起,问最大分数为多少. • n<=1 \(Sol\) 正解状态设得奇奇 ...
- Java迭代器源码解析
private class Itr implements Iterator<E> { int cursor; // 调用next方法返回的元素的索引 int lastRet = -1; / ...
- 推荐中的多任务学习-ESMM
本文将介绍阿里发表在 SIGIR'18 的论文ESMM<Entire Space Multi-Task Model: An Effective Approach for Estimating Po ...
- schedule of 2016-09-12~2016-09-18(Monday~Sunday)——1st semester of 2nd Grade
2016/9/12 Monday 1.send present to Teacher Wei&hu 2.make ppt for 1st database 2.0 meeting for al ...
- Go Web 编程之 模板(一)
概述 模板引擎是 Web 编程中必不可少的一个组件.模板能分离逻辑和数据,使得逻辑简洁清晰,并且模板可复用.引用第二篇文章<程序结构>一文中的图示,我们可以看到模板引擎在 Web 程序结构 ...
- Airbnb如何应用AARRR策略成为全球第一民宿平台
案例背景 基于房东和租客的痛点构建短租平台,但困于缓慢增长 2007年,住在美国旧金山的两位设计师——BrianChesky与Joe Gebbia正在为他们付不起房租而困扰.为了赚点外块,他们计划将阁 ...
- Asp.Net Core 3.0 Kestrel服务器下 高性能 WebSocket Server
最近研究.net core 的各种高性能类型,内存池之类的东西,基于kestrel 服务器的websocket ,写个例子练下手 把原生的Websocket用ArrayPool<T>,Me ...
- # 曹工说Spring Boot源码(10)-- Spring解析xml文件,到底从中得到了什么(context:annotation-config 解析)
写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...
- 非关系数据库与redis安装
1.什么是 NoSQL? NoSQL(NoSQL = Not Only SQL ),意为反 SQL 运动,是一项全新的数据库革命性运动,2000 年 前就有人提出,发展至 2009 年趋势越发高涨.它 ...
- hdu - 4965
One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learni ...