_WinAPI_GetTCPTable() 这个UDF怎么没了?
WinAPIex.au3没这东西了? 那个本来就不是函数库里的函数 ; #FUNCTION# ====================================================================================================================; Name...........: _WinAPI_GetTcpTable
; Description....: retrieves the IPv4 TCP connection table.
; Syntax.........: _WinAPI_GetTCPtable( ] )
; Parameters.....:
; Return values..: Success: TCPtable[][] = 2-D array
; = number of connections for connection n:
; = connection state (integer)
; = local IP
; = local port
; = remote IP
; = remote port
; = connection state (informative text)
; Failure: TCPtable = -1
; Author.........:
; Modified.......:
; Remarks........:
; Related........:
; Link...........: @@MsdnLink@@ GetTcpTable, MIB_TCPTABLE
; Example........: Yes
; ===============================================================================================================================
Func _WinAPI_GetTcpTable()
Local $TCPtable = [[-1]] ; preset to "failed"
Local $dwSize = DllStructCreate("dword") ; for MIB_TCPTABLE buffer size
Local $MIB_TCPTABLE = DllStructCreate("dword") ; nominal struct initially
DllStructSetData($dwSize, 1, 0) ; force zero size
Local $Ret = DllCall("iphlpapi.dll", "int", "GetTcpTable", "ptr", DllStructGetPtr($MIB_TCPTABLE), "ptr", DllStructGetPtr($dwSize), "int", 1) ; get size
If @error Or $Ret <> 122 Then Return $TCPtable ; dllCall error or RC is *not* ERROR_INSUFFICIENT_BUFFER = 122
$MIB_TCPTABLE = ""
For $i = 1 To DllStructGetData($dwSize, 1) / 4 ; make to requested size of buffer
$MIB_TCPTABLE &= "dword;"
Next
$MIB_TCPTABLE = DllStructCreate(StringTrimRight($MIB_TCPTABLE, 1)) ; requested struct
DllStructSetData($dwSize, 1, DllStructGetSize($MIB_TCPTABLE)) ; recheck its size
$Ret = DllCall("iphlpapi.dll", "int", "GetTcpTable", "ptr", DllStructGetPtr($MIB_TCPTABLE), "ptr", DllStructGetPtr($dwSize), "int", 1) ; get data
If @error Or $Ret Then Return $TCPtable ; dllCall error or RC is Error
Local $numTCPentries = DllStructGetData($MIB_TCPTABLE, 1) ; number of entries
ReDim $TCPtable[$numTCPentries + 1]
For $i = 1 To $numTCPentries
Local $Offset = ($i - 1) * 5 + 1 ; dword offset into struct
$TCPtable[$i] = DllStructGetData($MIB_TCPTABLE, $Offset + 1) ; integer connection state
$Ret = DllCall("ws2_32.dll", "str", "inet_ntoa", "uint", DllStructGetData($MIB_TCPTABLE, $Offset + 2)) ; local IP / translate
If @error Then Return $TCPtable ; dllCall error
$TCPtable[$i] = $Ret
$Ret = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($MIB_TCPTABLE, $Offset + 3)) ; local port / translate
If @error Then Return $TCPtable ; dllCall error
$TCPtable[$i] = $Ret
If $TCPtable[$i] <= 2 Then ; CLOSED or LISTENING state
$TCPtable[$i] = "0.0.0.0"
$TCPtable[$i] = 0
Else
$Ret = DllCall("ws2_32.dll", "str", "inet_ntoa", "uint", DllStructGetData($MIB_TCPTABLE, $Offset + 4)) ; remote IP / translate
If @error Then Return $TCPtable ; dllCall error
$TCPtable[$i] = $Ret
$Ret = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($MIB_TCPTABLE, $Offset + 5)) ; remote port / translate
If @error Then Return $TCPtable ; dllCall error
$TCPtable[$i] = $Ret
EndIf
Next
$dwSize = 0
$MIB_TCPTABLE = 0
$TCPtable = $numTCPentries ; success
Return $TCPtable
EndFunc ;==>_WinAPI_GetTcpTable
前来学习。。。。。。。。。。。。。。。
页:
[1]