python使用wmi模塊獲取windows下的系統(tǒng)信息 監(jiān)控系統(tǒng)
Python用WMI模塊獲取Windows系統(tǒng)的硬件信息:硬盤分區(qū)、使用情況,內(nèi)存大小,CPU型號(hào),當(dāng)前運(yùn)行的進(jìn)程,自啟動(dòng)程序及位置,系統(tǒng)的版本等信息。
本文實(shí)例講述了python使用wmi模塊獲取windows下的系統(tǒng)信息 監(jiān)控系統(tǒng)
#!/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 ()
#獲取操作系統(tǒng)版本
for sys in c.Win_OperatingSystem():
print "Version:%s" % sys.Caption.encode("UTF"),"Vernum:%s" % sys.BuildNumber
print sys.OSArchitecture.encode("UTF")#系統(tǒng)是位還是位的
print sys.NumberOfProcesses #當(dāng)前系統(tǒng)運(yùn)行的進(jìn)程總數(shù)
def cpu_mem():
c = wmi.WMI ()
#CPU類型和內(nèi)存
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 ()
#獲取硬盤分區(qū)
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()
以上內(nèi)容是關(guān)于python使用wmi模塊獲取windows下的系統(tǒng)信息 監(jiān)控系統(tǒng)的相關(guān)知識(shí),希望對(duì)大家有所幫助。
相關(guān)文章
python使用opencv換照片底色的實(shí)現(xiàn)
這篇文章主要介紹了python使用opencv換照片底色的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
Python的type()函數(shù)用法小結(jié)(最新推薦)
在本文中,深入探討了type()函數(shù)的用法,提供了詳細(xì)的示例代碼,并討論了其在Python編程中的實(shí)際應(yīng)用,通過學(xué)習(xí)如何正確使用type()函數(shù),可以更好地掌握Python編程,并寫出更可靠的代碼,需要的朋友可以參考下2024-07-07
Pycharm 解決自動(dòng)格式化沖突的設(shè)置操作
這篇文章主要介紹了Pycharm 解決自動(dòng)格式化沖突的設(shè)置操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-01-01
python3用PIL把圖片轉(zhuǎn)換為RGB圖片的實(shí)例
今天小編就為大家分享一篇python3用PIL把圖片轉(zhuǎn)換為RGB圖片的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-07-07
python批量制作雷達(dá)圖的實(shí)現(xiàn)方法
本文通過實(shí)例代碼介紹了如何用python批量制作雷達(dá)圖的實(shí)現(xiàn)方法,下面一起來看看如何實(shí)現(xiàn)的。2016-07-07
Python標(biāo)準(zhǔn)庫(kù)uuid模塊(生成唯一標(biāo)識(shí))詳解
uuid通過Python標(biāo)準(zhǔn)庫(kù)的uuid模塊生成通用唯一ID(或“UUID”)的一種快速簡(jiǎn)便的方法,下面這篇文章主要給大家介紹了關(guān)于Python標(biāo)準(zhǔn)庫(kù)uuid模塊(生成唯一標(biāo)識(shí))?的相關(guān)資料,需要的朋友可以參考下2022-05-05
Jupyter notebook 遠(yuǎn)程配置及SSL加密教程
這篇文章主要介紹了Jupyter notebook 遠(yuǎn)程配置及SSL加密教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-04-04

