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下的系统信息 监控系统

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

#!/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 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...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

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 get news data bypassing Investing.com's anti-crawler mechanism? How to get news data bypassing Investing.com's anti-crawler mechanism? Apr 02, 2025 am 07:03 AM

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...

Python 3.6 loading pickle file error ModuleNotFoundError: What should I do if I load pickle file '__builtin__'? Python 3.6 loading pickle file error ModuleNotFoundError: What should I do if I load pickle file '__builtin__'? Apr 02, 2025 am 06:27 AM

Loading pickle file in Python 3.6 environment error: ModuleNotFoundError:Nomodulenamed...

What is the reason why pipeline files cannot be written when using Scapy crawler? What is the reason why pipeline files cannot be written when using Scapy crawler? Apr 02, 2025 am 06:45 AM

Discussion on the reasons why pipeline files cannot be written when using Scapy crawlers When learning and using Scapy crawlers for persistent data storage, you may encounter pipeline files...

See all articles