zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    金思维仪器设备管理系统
    一道趣味数学题(二)
    三个和尚没水喝
    VBA从人民银行网站获取5个币种的历史汇率信息
    亿图图示专家 专业流程图,网络拓扑图,组织结构图设计软件
    Safari 近乎完美!闪电侠苹果Safari 4评测
    身体器官工作表一览,别熬夜
    Windows 7(32位)简体中文旗舰版OEM光盘
    金思维仪器设备管理系统产品上线啦
    VBA代码控制DTPicker控件的下拉日期表显示
  • 原文地址:https://www.cnblogs.com/liu-ke/p/4911244.html
Copyright © 2011-2022 走看看