Home Backend Development Python Tutorial python使用wmi模块获取windows下的系统信息 监控系统

python使用wmi模块获取windows下的系统信息 监控系统

Jun 10, 2016 pm 03:07 PM

Python用WMI模块获取Windows系统的硬件信息:硬盘分区、使用情况,内存大小,CPU型号,当前运行的进程,自启动程序及位置,系统的版本等信息。

本文实例讲述了python使用wmi模块获取windows下的系统信息 监控系统

 #!/usr/bin/env python 
 # -*- coding: utf- -*- 
 #http://www.cnblogs.com/liu-ke/
 import wmi 
 import os 
 import sys 
 import platform 
 import time 
 def sys_version(): 
   c = wmi.WMI () 
   #获取操作系统版本 
   for sys in c.Win_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.Win_Processor(): 
     #print "Processor ID: %s" % processor.DeviceID 
     print "Process Name: %s" % processor.Name.strip() 
   for Memory in c.Win_PhysicalMemory(): 
     print "Memory Capacity: %.fMB" %(int(Memory.Capacity)/) 
 def disk(): 
   c = wmi.WMI ()  
   #获取硬盘分区 
   for physical_disk in c.Win_DiskDrive (): 
     for partition in physical_disk.associators ("Win_DiskDriveToDiskPartition"): 
       for logical_disk in partition.associators ("Win_LogicalDiskToPartition"): 
         print physical_disk.Caption.encode("UTF"), partition.Caption.encode("UTF"), logical_disk.Caption 
   #获取硬盘使用百分情况 
   for disk in c.Win_LogicalDisk (DriveType=): 
     print disk.Caption, "%.f%% free" % (. * long (disk.FreeSpace) / long (disk.Size)) 
 def network(): 
   c = wmi.WMI ()  
   #获取MAC和IP地址 
   for interface in c.Win_NetworkAdapterConfiguration (IPEnabled=): 
     print "MAC: %s" % interface.MACAddress 
   for ip_address in interface.IPAddress: 
     print "ip_add: %s" % ip_address 
   print 
 def main(): 
   sys_version() 
   cpu_mem() 
   #disk() 
   #network() 
 if __name__ == '__main__': 
   main() 
   print platform.system() 
   print platform.release() 
   print platform.version() 
   print platform.platform() 
   print platform.machine()
Copy after login

以上内容是关于python使用wmi模块获取windows下的系统信息 监控系统的相关知识,希望对大家有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

What are regular expressions? What are regular expressions? Mar 20, 2025 pm 06:25 PM

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

What are some popular Python libraries and their uses? What are some popular Python libraries and their uses? Mar 21, 2025 pm 06:46 PM

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

How to dynamically create an object through a string and call its methods in Python? How to dynamically create an object through a string and call its methods in Python? Apr 01, 2025 pm 11:18 PM

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

See all articles