;xp sp3 ;不能获取usb,虚拟,禁用的网卡
#Include <Array.au3>
Opt('MustDeclareVars', 1)
Global Const $MIB_IF_TYPE_OTHER = 1
Global Const $MIB_IF_TYPE_ETHERNET_CSMACD = 6
Global Const $MIB_IF_TYPE_ISO88025_TOKENRING = 9
Global Const $MIB_IF_TYPE_PPP = 23
Global Const $MIB_IF_TYPE_SOFTWARE_LOOPBACK = 24
Global Const $MIB_IF_TYPE_ATM = 37
Global Const $MIB_IF_TYPE_IEEE80211 = 71
Global Const $MIB_IF_TYPE_TUNNEL = 131
Global Const $MIB_IF_TYPE_IEEE1394 = 144
Global Const $MIB_IF_ADMIN_STATUS_UP = 1
Global Const $MIB_IF_ADMIN_STATUS_DOWN = 2
Global Const $MIB_IF_ADMIN_STATUS_TESTING = 3
Global Const $MIB_IF_OPER_STATUS_NON_OPERATIONAL = 0
Global Const $MIB_IF_OPER_STATUS_UNREACHABLE = 1
Global Const $MIB_IF_OPER_STATUS_DISCONNECTED = 2
Global Const $MIB_IF_OPER_STATUS_CONNECTING = 3
Global Const $MIB_IF_OPER_STATUS_CONNECTED = 4
Global Const $MIB_IF_OPER_STATUS_OPERATIONAL = 5
Global Const $tagMIB_IFROW = 'wchar Name[256];dword Index;dword Type;dword Mtu;dword Speed;dword PhysAddrLen;byte PhysAddr[8];dword AdminStatus;dword OperStatus;dword LastChange;dword InOctets;dword InUcastPkts;dword InNUcastPkts;dword InDiscards;dword InErrors;dword InUnknownProtos;dword OutOctets;dword OutUcastPkts;dword OutNUcastPkts;dword OutDiscards;dword OutErrors;dword OutQLen;dword DescrLen;char Descr[256]'
Global $hParent, $hForm, $Dll, $Msg, $Combo, $Label1, $Label2, $Timer, $Data, $Index = 0, $pIndex = 0, $Adapter[1][3] = [[0]]
$Dll = DllOpen('IPHlpApi.dll')
dim $Data1,$Data2,$index=2 ;修改$index值
$Data1 = _WinAPI_GetIfEntry($index, $Dll)
While 1
sleep(1000)
$Data2 = _WinAPI_GetIfEntry($index, $Dll)
ToolTip('下行:'&Round(($Data2[8]-$Data1[8])/1024,2)&' /上行:'&Round(($Data2[14]-$Data1[14])/1024,2),120,0)
$Data1[14]=$Data2[14]
$Data1[8]=$Data2[8]
wend
Func _WinAPI_GetIfEntry($iIndex, $Dll = -1)
Local $Ret, $Data, $Addr, $Count
Local $tMIB_IFROW
If $Dll < 0 Then
$Dll = 'IPHlpApi.dll'
EndIf
$tMIB_IFROW = DllStructCreate($tagMIB_IFROW)
DllStructSetData($tMIB_IFROW, 2, $iIndex)
$Ret = DLLCall($Dll, 'dword', 'GetIfEntry', 'ptr', DllStructGetPtr($tMIB_IFROW))
If (@error) Or ($Ret[0]) Then
Return SetError($Ret[0], 0, 0)
EndIf
Dim $Data[20]
$Data[0 ] = DllStructGetData($tMIB_IFROW, 'Name')
$Data[1 ] = $iIndex
$Data[2 ] = DllStructGetData($tMIB_IFROW, 'Type')
$Data[3 ] = DllStructGetData($tMIB_IFROW, 'Mtu')
$Data[4 ] = DllStructGetData($tMIB_IFROW, 'Speed')
$Count = DllStructGetData($tMIB_IFROW, 'PhysAddrLen')
$Addr = ''
For $i = 1 To $Count
$Addr &= Hex(DllStructGetData($tMIB_IFROW, 'PhysAddr', $i), 2) & '-'
Next
$Data[5 ] = StringTrimRight($Addr, 1)
$Data[6 ] = DllStructGetData($tMIB_IFROW, 'AdminStatus')
$Data[7 ] = DllStructGetData($tMIB_IFROW, 'OperStatus')
$Data[8 ] = DllStructGetData($tMIB_IFROW, 'InOctets')
$Data[9 ] = DllStructGetData($tMIB_IFROW, 'InUcastPkts')
$Data[10] = DllStructGetData($tMIB_IFROW, 'InNUcastPkts')
$Data[11] = DllStructGetData($tMIB_IFROW, 'InDiscards')
$Data[12] = DllStructGetData($tMIB_IFROW, 'InErrors')
$Data[13] = DllStructGetData($tMIB_IFROW, 'InUnknownProtos')
$Data[14] = DllStructGetData($tMIB_IFROW, 'OutOctets')
$Data[15] = DllStructGetData($tMIB_IFROW, 'OutUcastPkts')
$Data[16] = DllStructGetData($tMIB_IFROW, 'OutNUcastPkts')
$Data[17] = DllStructGetData($tMIB_IFROW, 'OutDiscards')
$Data[18] = DllStructGetData($tMIB_IFROW, 'OutErrors')
$Data[19] = StringLeft(DllStructGetData($tMIB_IFROW, 'Descr'), DllStructGetData($tMIB_IFROW, 'DescrLen') - 1)
Return $Data
EndFunc ;==>_WinAPI_GetIfEntry