欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python使用WMI檢測windows系統(tǒng)信息、硬盤信息、網卡信息的方法

 更新時間:2015年05月15日 15:21:03   作者:令狐不聰  
這篇文章主要介紹了python使用WMI檢測windows系統(tǒng)信息、硬盤信息、網卡信息的方法,涉及Python針對系統(tǒng)信息的相關操作技巧,需要的朋友可以參考下

本文實例講述了python使用WMI檢測windows系統(tǒng)信息、硬盤信息、網卡信息的方法。分享給大家供大家參考。具體實現方法如下:

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
import wmi 
import sys,time,platform 
def get_system_info(os): 
  """ 
  獲取操作系統(tǒng)版本。 
  """ 
  print 
  print "Operating system:" 
  if os == "Windows": 
    c = wmi.WMI () 
    for sys in c.Win32_OperatingSystem(): 
      print '\t' + "Version :\t%s" % sys.Caption.encode("GBK") 
      print '\t' + "Vernum :\t%s" % sys.BuildNumber 
def get_memory_info(os): 
  """ 
  獲取物理內存和虛擬內存。 
  """ 
  print 
  print "memory_info:" 
  if os == "Windows": 
    c = wmi.WMI () 
    cs = c.Win32_ComputerSystem() 
    pfu = c.Win32_PageFileUsage() 
    MemTotal = int(cs[0].TotalPhysicalMemory)/1024/1024 
    print '\t' + "TotalPhysicalMemory :" + '\t' + str(MemTotal) + "M" 
    #tmpdict["MemFree"] = int(os[0].FreePhysicalMemory)/1024 
    SwapTotal = int(pfu[0].AllocatedBaseSize) 
    print '\t' + "SwapTotal :" + '\t' + str(SwapTotal) + "M" 
    #tmpdict["SwapFree"] = int(pfu[0].AllocatedBaseSize - pfu[0].CurrentUsage) 
def get_disk_info(os): 
  """ 
  獲取物理磁盤信息。 
  """ 
  print 
  print "disk_info:" 
  if os == "Windows": 
    tmplist = [] 
    c = wmi.WMI () 
    for physical_disk in c.Win32_DiskDrive(): 
      if physical_disk.Size: 
        print '\t' + str(physical_disk.Caption) + ' :\t' + str(long(physical_disk.Size)/1024/1024/1024) + "G" 
def get_cpu_info(os): 
  """ 
  獲取CPU信息。 
  """ 
  print 
  print "cpu_info:" 
  if os == "Windows": 
    tmpdict = {} 
    tmpdict["CpuCores"] = 0 
    c = wmi.WMI () 
    for cpu in c.Win32_Processor():       
      tmpdict["CpuType"] = cpu.Name 
    try: 
      tmpdict["CpuCores"] = cpu.NumberOfCores 
    except: 
      tmpdict["CpuCores"] += 1 
      tmpdict["CpuClock"] = cpu.MaxClockSpeed   
    print '\t' + 'CpuType :\t' + str(tmpdict["CpuType"]) 
    print '\t' + 'CpuCores :\t' + str(tmpdict["CpuCores"]) 
def get_network_info(os): 
  """ 
  獲取網卡信息和當前TCP連接數。 
  """ 
  print 
  print "network_info:" 
  if os == "Windows": 
    tmplist = [] 
    c = wmi.WMI () 
    for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): 
        tmpdict = {} 
        tmpdict["Description"] = interface.Description 
        tmpdict["IPAddress"] = interface.IPAddress[0] 
        tmpdict["IPSubnet"] = interface.IPSubnet[0] 
        tmpdict["MAC"] = interface.MACAddress 
        tmplist.append(tmpdict) 
    for i in tmplist: 
      print '\t' + i["Description"] 
      print '\t' + '\t' + "MAC :" + '\t' + i["MAC"] 
      print '\t' + '\t' + "IPAddress :" + '\t' + i["IPAddress"] 
      print '\t' + '\t' + "IPSubnet :" + '\t' + i["IPSubnet"] 
    for interfacePerfTCP in c.Win32_PerfRawData_Tcpip_TCPv4(): 
        print '\t' + 'TCP Connect :\t' + str(interfacePerfTCP.ConnectionsEstablished) 
if __name__ == "__main__": 
  os = platform.system() 
  get_system_info(os) 
  get_memory_info(os) 
  get_disk_info(os) 
  get_cpu_info(os) 
  get_network_info(os) 

希望本文所述對大家的Python程序設計有所幫助。

相關文章

  • 用于業(yè)余項目的8個優(yōu)秀Python庫

    用于業(yè)余項目的8個優(yōu)秀Python庫

    今天小編就為大家分享一篇用于業(yè)余項目的8個大型Python庫,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-09-09
  • Python 模擬員工信息數據庫操作的實例

    Python 模擬員工信息數據庫操作的實例

    下面小編就為大家?guī)硪黄狿ython 模擬員工信息數據庫操作的實例。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • python抓取網頁中鏈接的靜態(tài)圖片

    python抓取網頁中鏈接的靜態(tài)圖片

    這篇文章主要為大家詳細介紹了python抓取網頁中鏈接的靜態(tài)圖片,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • python和js交互調用的方法

    python和js交互調用的方法

    在本篇文章里小編給大家整理了關于python和js交互調用的方法,需要的方法可以參考學習下。
    2020-06-06
  • python動態(tài)規(guī)劃算法實例詳解

    python動態(tài)規(guī)劃算法實例詳解

    在本篇文章里小編給大家整理了關于python動態(tài)規(guī)劃算法實例內容,有需要的朋友們可以參考學習下。
    2020-11-11
  • python實現猜數字游戲(無重復數字)示例分享

    python實現猜數字游戲(無重復數字)示例分享

    這篇文章主要介紹了python實現猜數字游戲(無重復數字)示例,需要的朋友可以參考下
    2014-03-03
  • django中嵌套的try-except實例

    django中嵌套的try-except實例

    這篇文章主要介紹了django中嵌套的try-except實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05
  • python讀取與寫入csv格式文件的示例代碼

    python讀取與寫入csv格式文件的示例代碼

    本篇文章主要介紹了python讀取與寫入csv格式文件的示例代碼,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • Python數據結構與算法之字典樹實現方法示例

    Python數據結構與算法之字典樹實現方法示例

    這篇文章主要介紹了Python數據結構與算法之字典樹實現方法,可實現針對單詞出現次數的統(tǒng)計功能,涉及Python樹結構的定義、遍歷及統(tǒng)計等相關操作技巧,需要的朋友可以參考下
    2017-12-12
  • 教你怎么用Python實現多路徑迷宮

    教你怎么用Python實現多路徑迷宮

    這篇文章主要介紹了教你怎么用Python實現多路徑迷宮,文中有非常詳細的代碼示例,對正在學習python的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-04-04

最新評論