# -*- 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