python使用WMI檢測(cè)windows系統(tǒng)信息、硬盤(pán)信息、網(wǎng)卡信息的方法
本文實(shí)例講述了python使用WMI檢測(cè)windows系統(tǒng)信息、硬盤(pán)信息、網(wǎng)卡信息的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
#!/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):
"""
獲取物理內(nèi)存和虛擬內(nèi)存。
"""
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):
"""
獲取物理磁盤(pán)信息。
"""
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):
"""
獲取網(wǎng)卡信息和當(dāng)前TCP連接數(shù)。
"""
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)
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
- Python 使用指定的網(wǎng)卡發(fā)送HTTP請(qǐng)求的實(shí)例
- python 的 scapy庫(kù),實(shí)現(xiàn)網(wǎng)卡收發(fā)包的例子
- Python選擇網(wǎng)卡發(fā)包及接收數(shù)據(jù)包
- Python簡(jiǎn)單獲取網(wǎng)卡名稱(chēng)及其IP地址的方法【基于psutil模塊】
- Python獲取本機(jī)所有網(wǎng)卡ip,掩碼和廣播地址實(shí)例代碼
- Linux服務(wù)器網(wǎng)卡流量查看方法 shell和Python各一枚
- Python腳本實(shí)現(xiàn)網(wǎng)卡流量監(jiān)控
- python監(jiān)控網(wǎng)卡流量并使用graphite繪圖的示例
- python 獲取計(jì)算機(jī)的網(wǎng)卡信息
相關(guān)文章
用于業(yè)余項(xiàng)目的8個(gè)優(yōu)秀Python庫(kù)
今天小編就為大家分享一篇用于業(yè)余項(xiàng)目的8個(gè)大型Python庫(kù),小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-09-09
Python 模擬員工信息數(shù)據(jù)庫(kù)操作的實(shí)例
下面小編就為大家?guī)?lái)一篇Python 模擬員工信息數(shù)據(jù)庫(kù)操作的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
python抓取網(wǎng)頁(yè)中鏈接的靜態(tài)圖片
這篇文章主要為大家詳細(xì)介紹了python抓取網(wǎng)頁(yè)中鏈接的靜態(tài)圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01
python動(dòng)態(tài)規(guī)劃算法實(shí)例詳解
在本篇文章里小編給大家整理了關(guān)于python動(dòng)態(tài)規(guī)劃算法實(shí)例內(nèi)容,有需要的朋友們可以參考學(xué)習(xí)下。2020-11-11
python實(shí)現(xiàn)猜數(shù)字游戲(無(wú)重復(fù)數(shù)字)示例分享
這篇文章主要介紹了python實(shí)現(xiàn)猜數(shù)字游戲(無(wú)重復(fù)數(shù)字)示例,需要的朋友可以參考下2014-03-03
Python數(shù)據(jù)結(jié)構(gòu)與算法之字典樹(shù)實(shí)現(xiàn)方法示例
這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)與算法之字典樹(shù)實(shí)現(xiàn)方法,可實(shí)現(xiàn)針對(duì)單詞出現(xiàn)次數(shù)的統(tǒng)計(jì)功能,涉及Python樹(shù)結(jié)構(gòu)的定義、遍歷及統(tǒng)計(jì)等相關(guān)操作技巧,需要的朋友可以參考下2017-12-12

