找回密码
 加入
搜索
查看: 1844|回复: 3

[网络通信] _WinAPI_GetTCPTable() 这个UDF怎么没了?

[复制链接]
发表于 2014-10-30 16:25:16 | 显示全部楼层 |阅读模式
WinAPIex.au3没这东西了?
发表于 2014-10-30 19:49:38 | 显示全部楼层
那个本来就不是函数库里的函数
发表于 2014-10-31 08:57:42 | 显示全部楼层
[au3]; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_GetTcpTable
; Description....: retrieves the IPv4 TCP connection table.
; Syntax.........: _WinAPI_GetTCPtable( [optional handle to "ws2_32.dll" [, optional handle to "iphlpapi.dll" ] ] )
; Parameters.....:
; Return values..: Success:    TCPtable[][] = 2-D array
;                              [0][0] = number of connections for connection n:
;                              [n][0] = connection state (integer)
;                              [n][1] = local IP
;                              [n][2] = local port
;                              [n][3] = remote IP
;                              [n][4] = remote port
;                              [n][5] = connection state (informative text)
;                  Failure:    TCPtable[0][0] = -1
; Author.........:
; Modified.......:
; Remarks........:
; Related........:
; Link...........: @@MsdnLink@@ GetTcpTable, MIB_TCPTABLE
; Example........: Yes
; ===============================================================================================================================

Func _WinAPI_GetTcpTable()

        Local $TCPtable[1][1] = [[-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[0] <> 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[0] Then Return $TCPtable ; dllCall error or RC is Error

        Local $numTCPentries = DllStructGetData($MIB_TCPTABLE, 1) ; number of entries
        ReDim $TCPtable[$numTCPentries + 1][6]

        For $i = 1 To $numTCPentries
                Local $Offset = ($i - 1) * 5 + 1 ; dword offset into struct
                $TCPtable[$i][0] = 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][1] = $Ret[0]
                $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][2] = $Ret[0]

                If $TCPtable[$i][0] <= 2 Then ; CLOSED or LISTENING state
                        $TCPtable[$i][3] = "0.0.0.0"
                        $TCPtable[$i][4] = 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][3] = $Ret[0]
                        $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][4] = $Ret[0]
                EndIf
        Next

        $dwSize = 0
        $MIB_TCPTABLE = 0
        $TCPtable[0][0] = $numTCPentries ; success
        Return $TCPtable

EndFunc   ;==>_WinAPI_GetTcpTable

[/au3]
发表于 2014-11-5 20:56:05 | 显示全部楼层
前来学习。。。。。。。。。。。。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-3 12:21 , Processed in 0.093633 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表