您的位置:首页 > 编程语言 > Python开发

python利用wmi模块统计windows下网卡信息和连接数

2012-09-03 13:55 766 查看
# -*- coding: utf-8 -*-

#import

########################################################################

import os, sys

import time

import wmi

########################################################################

#function

########################################################################

def get_network_info() :

tmplist = []

c = wmi.WMI ()

intfid1 = 0

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

tmpdict["MTU"] = interface.MTU

intfid2 = 0

for interfacePerf in c.Win32_PerfFormattedData_Tcpip_NetworkInterface():

if intfid1 == intfid2:

dir(interfacePerf)

tmpdict["BytesRSec"] = interfacePerf.BytesReceivedPerSec

tmpdict["BytesSSec"] = interfacePerf.BytesSentPerSec

tmpdict["BytesRPkg"] = interfacePerf.PacketsReceivedPersec

tmpdict["BytesSPkg"] = interfacePerf.PacketsSentPersec

intfid2 += 1

tmplist.append(tmpdict)

intfid1 += 1

return tmplist

def tcpvalues():

c = wmi.WMI ()

for interfacePerfTCP in c.Win32_PerfRawData_Tcpip_TCPv4():

return interfacePerfTCP.ConnectionsEstablished

if __name__ == "__main__":

print '-------------------'

print get_network_info()

print '-------------------'

print tcpvalues()
其他python网站访问地址:http://bbs.pythonfan.org/thread-2347-1-1.html本文出自 “学海无涯苦作伴” 博客,请务必保留此出处http://linuxshow.blog.51cto.com/1572053/980632
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: