監測windows記憶體等系統引數模組 wmi

2021-06-20 07:45:48 字數 2993 閱讀 3622

安裝:

exe安裝包無法識別2.7以上版本

例子:

#!/usr/bin/env python 

# -*- coding: utf-8 -*-

import wmi

import os

import sys

import platform

import time

def sys_version():

c = wmi.wmi ()

#獲取作業系統版本

for sys in c.win32_operatingsystem():

print "version:%s" % sys.caption.encode("utf8"),"vernum:%s" % sys.buildnumber

print sys.osarchitecture.encode("utf8")#系統是32位還是64位的

print sys.numberofprocesses #當前系統執行的程序總數

def cpu_mem():

c = wmi.wmi ()

#cpu型別和記憶體

for processor in c.win32_processor():

#print "processor id: %s" % processor.deviceid

print "process name: %s" % processor.name.strip()

for memory in c.win32_physicalmemory():

print "memory capacity: %.fmb" %(int(memory.capacity)/1048576)

def cpu_use():

#5s取一次cpu的使用率

c = wmi.wmi()

count=0

while true:

for cpu in c.win32_processor():

timestamp = time.strftime('%a, %d %b %y %h:%m:%s', time.localtime())

print '%s | utilization: %s: %d %%' % (timestamp, cpu.deviceid, cpu.loadpercentage)

time.sleep(2)

count+=1

if count==3:

break

def disk():

c = wmi.wmi ()

#獲取硬碟分割槽

for physical_disk in c.win32_diskdrive ():

for partition in physical_disk.associators ("win32_diskdrivetodiskpartition"):

for logical_disk in partition.associators ("win32_logicaldisktopartition"):

print physical_disk.caption.encode("utf8"), partition.caption.encode("utf8"), logical_disk.caption

#獲取硬碟使用百分情況

for disk in c.win32_logicaldisk (drivetype=3):

print disk.caption, "%0.2f%% free" % (100.0 * long (disk.freespace) / long (disk.size))

def network():

c = wmi.wmi ()

#獲取mac和ip位址

for inte***ce in c.win32_networkadapterconfiguration (ipenabled=1):

print "mac: %s" % inte***ce.macaddress

for ip_address in inte***ce.ipaddress:

print "ip_add: %s" % ip_address

print

## #獲取自啟動程式的位置

## for s in c.win32_startupcommand ():

## print "[%s] %s <%s>" % (s.locatio.encode("utf8"), s.caption.encode("utf8"), s.command.encode("utf8"))

## #獲取當前執行的程序

## for process in c.win32_process ():

## print process.processid, process.name

def main():

print "*****===version*****==="

sys_version()

print "*****===cpu memory*****"

cpu_mem()

print "*****===disk**********="

disk()

print "*****===network*****==="

network()

print "*****===cpu use*****==="

cpu_use()

if __name__ == '__main__':

main()

## print platform.system()

## print platform.release()

## print platform.version()

## print platform.platform()

## print platform.machine()

C 讀寫記憶體 可變參方法未寫完 等完善

include stdafx.h 定義讀取記憶體的方法 dword r4 dword base 可變參函式 用來讀取記憶體 dword r4 dword base,定義寫記憶體的方法 bool w4 dword base,float dwvalue debugview除錯 過濾頭 qidai voi...

CentOS檢視CPU 記憶體 版本等系統資訊

centos檢視系統資訊 一 檢視cpu more proc cpuinfo grep model name grep model name proc cpuinfo 如果覺得需要看的更加舒服 grep model name proc cpuinfo cut f2 d 二 檢視記憶體 grep me...

linux檢視cpu 記憶體 io 系統負載等

檢視cpu使用情況的命令 vmstat 5 每5秒重新整理一次,最右側有cpu的佔用率的資料 toptop 然後按shift p,按照程序處理器佔用率排序 檢視記憶體使用情況的命令 free 用free命令檢視記憶體占用情況 toptop 然後按shift m,按照程序記憶體佔用率排序 檢視磁碟i ...