利用python 与 wmi 获取WINDOWS基本信息
#!/usr/bin/env python3.5
# -*- coding:utf8 -*-
import platform
import subprocess
import wmi
def services():
c = wmi.WMI()
for s in c.Win32_Service (StartMode="Auto", State="Stopped"):
if input ("Restart %s? " % s.Caption).upper () == "Y":
s.StartService ()
def sys_version():
c = wmi.WMI ()
#获取操作系统版本
for sys in c.Win32_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.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 network():
c = wmi.WMI ()
#获取MAC和IP地址
for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled= True):
print ("MAC: %s" % interface.MACAddress )
for ip_address in interface.IPAddress:
print ("ip_add: %s" % ip_address ) def w_disk(): c = wmi.WMI()
i = 0
# 获取磁盘信息
for disk in c.Win32_LogicalDisk (DriveType=3):
# print(disk)
# 可用大小G
a = round(int(disk.FreeSpace) / (1024*1024*1024),2)
print(a)
# 可用大小%
b = int(100.0 * float(disk.FreeSpace) /float(disk.Size))
print(b)
if disk.Caption == "c:":
if (a < 2) or (b < 10):
i += 1
else:
i += 0
else:
if (a < 10) or (b < 10):
i += 1
else:
i += 0
print (i) def L_disk():
free = subprocess.getstatusoutput('df -h|grep dev|egrep -v "tmp|var|shm"')
list = free[1].split('\n')
i = 0
for disk in range(len(list)):
vd = list[disk][6:8]
a = list[disk].split()[3]
if a[-1] == 'T':
a = int(float(a[:-1]))*1024
else:
a = int(float(a[:-1]))
b = 100 - int(list[disk].split()[4][:-1])
if vd == "da":
if (a < 2) or (b < 10):
i += 1
else:
i += 0
else:
if (a < 10) or (b < 10):
i += 1
else:
i += 0
print (i) if __name__ == "__main__":
os = platform.system()
if os == "Windows":
# w_disk()
# sys_version()
# cpu_mem()
# network()
services()
elif os == "Linux":
L_disk()
利用python 与 wmi 获取WINDOWS基本信息的更多相关文章
- 用PYTHON + PYWIN32 + WMI获取WINDOWS系统基本信息
网上原码,去了DECODE编码的问题. PyScripter这个PYTHON的IDE工具在WIN下表现不错哟. 感觉比SPYDER,ERIC,SUBLEME TEXT3之类的好用呀.. #!/usr/ ...
- Python使用wmi获取Windows相关信息
在使用Python获取Windows系统上的相关的信息可以使用WMI接口来获取, 什么是wmi? WMI是一项核心的Windows管理技术,WMI作为一种规范和基础结构,通过它可以访问.配置.管理和监 ...
- Python的功能模块[0] -> wmi -> 获取 Windows 内部信息
wmi模块 / wmi Module WMI (Windows Management Instrumentation) 模块可用于获取 Windows 内部信息.该模块需要 win32com 的支持, ...
- 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 通过wmi获取Window服务器硬件信息
通过pip install wmi安装wmi 查看cpu序列号: wmic cpu get processorid 查看主板序列号: wmic baseboard get serialnumber 查 ...
- python配合Fiddler获取windows app登录时生成cookie实例
工具Fiddler/python3 打开Fiddler,清空一下Fidder里面的请求记录 打开app,进行登录,注意Fiddler里的请求变化 在弹出app登录的时候Fiddler里已经有了四个请求 ...
- 一篇文章教会你利用Python网络爬虫获取电影天堂视频下载链接
[一.项目背景] 相信大家都有一种头疼的体验,要下载电影特别费劲,对吧?要一部一部的下载,而且不能直观的知道最近电影更新的状态. 今天小编以电影天堂为例,带大家更直观的去看自己喜欢的电影,并且下载下来 ...
- 某校高中生利用Python,巧妙获取考试成绩,看到成绩后无言以对!
Python是非常有吸引力的编程语言,学习Python的不是帅哥就是美女.为什么这么说呢?因为我和我的女朋友都是学习Python认识的,小编肯定是帅哥,不用去怀疑,而且我眼光特高. 给大伙讲一个故事, ...
随机推荐
- (翻译) Android Accounts Api使用指南
本文翻译自Udinic的文章Write your own Android Authenticator,可能需要FQ才能阅读.这是译者目前能找到的介绍如何使用Android的Accounts Api最好 ...
- Win32_Battery class
wmi的Win32_Battery类实现 其中EstimatedChargeRemaining属性返回剩余电量的百分比,EstimatedRunTime属性返回剩余时间(分钟) 其他属性参考http: ...
- (转)js网址验证
这个url的正则表达式判断的js!是比较全面的.它验证的情况包括!IP,域名(domain),ftp,二级域名,域名中的文件,域名加上端口!是我见过的最全面的url验证了!可能还有遗漏的! <s ...
- CodeBlocks的下载安装、配置、简单编程
CodeBlocks的下载安装.配置.简单编程 IDE简介 http://www.baidu.com/s?wd=codeblocks ,这里只是介绍Windows平台下的IDE环境配置. CodeBl ...
- 使用upstream和subrequest访问第三方服务
本文是对陶辉<深入理解Nginx>第5章内容的梳理以及实现,代码和注释基本出自此书. 一.upstream:以向nginx服务器的请求转化为向google服务器的搜索请求为例 (一)模块框 ...
- Mathematics for Computer Graphics
Mathematics for Computer Graphics 最近严重感觉到数学知识的不足! http://bbs.gameres.com/showthread.asp?threadid=105 ...
- How to make workflow chart using several tools in Linux?
Just as what I said, I usually use yED to make workflow chart and markdown as the language to write ...
- IE11仿真文档模式默认IE5 IE7的调整办法
<meta http-equiv="X-UA-Compatible" content="IE=edge">
- HTML meta viewport属性
什么是Viewport 手机浏览器是把页面放在一个虚拟的“窗口”(viewport)中,通常这个虚拟的“窗口”(viewport)比屏幕宽,这样就不用把每个网页挤到很小的窗口中(这样会破坏没有针对手机 ...
- Python学习--10 面向对象编程
面向对象编程--Object Oriented Programming,简称OOP,是一种程序设计思想.OOP把对象作为程序的基本单元,一个对象包含了数据和操作数据的函数. 本节对于面向对象的概念不做 ...