日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python使用wmi模塊獲取windows下的系統信息 監控系統

系統 1766 0

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()
          

以上內容是關于python使用wmi模塊獲取windows下的系統信息 監控系統的相關知識,希望對大家有所幫助。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 西安市| 利川市| 南澳县| 米泉市| 南京市| 山东省| 武胜县| 车险| 无为县| 武宣县| 昌都县| 兴化市| 札达县| 庆元县| 汪清县| 余庆县| 太康县| 那坡县| 白银市| 晋中市| 阿城市| 凉山| 榆林市| 聂荣县| 新竹县| 喜德县| 四川省| 滨海县| 出国| 广河县| 准格尔旗| 温州市| 仪陇县| 寿阳县| 余干县| 巴青县| 贡嘎县| 天全县| 商城县| 南昌市| 卓资县|