Python WMI获取Windows系统信息 监控系统
2021/4/23 7:27:36
本文主要是介绍Python WMI获取Windows系统信息 监控系统,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Python通过WMI模块获取Windows系统信息,对系统参数进行监控。
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 #http://www.cnblogs.com/liu-ke/ 4 import wmi 5 import os 6 import sys 7 import platform 8 import time 9 10 def sys_version(): 11 c = wmi.WMI () 12 #获取操作系统版本 13 for sys in c.Win32_OperatingSystem(): 14 print "Version:%s" % sys.Caption.encode("UTF8"),"Vernum:%s" % sys.BuildNumber 15 print sys.OSArchitecture.encode("UTF8")#系统是32位还是64位的 16 print sys.NumberOfProcesses #当前系统运行的进程总数17 18 def cpu_mem(): 19 c = wmi.WMI () 20 #CPU类型和内存 21 for processor in c.Win32_Processor(): 22 #print "Processor ID: %s" % processor.DeviceID 23 print "Process Name: %s" % processor.Name.strip() 24 for Memory in c.Win32_PhysicalMemory(): 25 print "Memory Capacity: %.fMB" %(int(Memory.Capacity)/1048576) 26 27 28 29 def disk(): 30 c = wmi.WMI () 31 #获取硬盘分区 32 for physical_disk in c.Win32_DiskDrive (): 33 for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"): 34 for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"): 35 print physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8"), logical_disk.Caption 36 37 #获取硬盘使用百分情况 38 for disk in c.Win32_LogicalDisk (DriveType=3): 39 print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size)) 40 41 def network(): 42 c = wmi.WMI () 43 #获取MAC和IP地址 44 for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): 45 print "MAC: %s" % interface.MACAddress 46 for ip_address in interface.IPAddress: 47 print "ip_add: %s" % ip_address 48 print 49 50 51 def main(): 52 sys_version() 53 cpu_mem() 54 #disk() 55 #network() 56 57 if __name__ == '__main__': 58 main() 59 print platform.system() 60 print platform.release() 61 print platform.version() 62 print platform.platform() 63 print platform.machine()
这篇关于Python WMI获取Windows系统信息 监控系统的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程