找回密码
 加入
搜索
查看: 3006|回复: 2

[AU3基础] 关于_WinAPI_GetTCPTable求教

[复制链接]
发表于 2014-4-14 17:59:31 | 显示全部楼层 |阅读模式
我在GoogleCode的SVN上几乎翻遍了N种版本的WinAPIEx.au3文件, 都没有找到该函数
麻烦大侠给个能用的WinAPIEx.au3

相关帖子

 楼主| 发表于 2014-4-14 18:22:13 | 显示全部楼层
暂时找到了一个不错的替代方案, 原文在此
#include <Array.au3>

Global Enum $TCP_TABLE_BASIC_LISTENER, $TCP_TABLE_BASIC_CONNECTIONS, $TCP_TABLE_BASIC_ALL, $TCP_TABLE_OWNER_PID_LISTENER, $TCP_TABLE_OWNER_PID_CONNECTIONS, _
        $TCP_TABLE_OWNER_PID_ALL, $TCP_TABLE_OWNER_MODULE_LISTENER, $TCP_TABLE_OWNER_MODULE_CONNECTIONS, $TCP_TABLE_OWNER_MODULE_ALL

;    $TCP_TABLE_OWNER_MODULE_... not working for now

Global $aTcpTable = _WinAPI_GetTcpTable()
_ArrayDisplay($aTcpTable, "TCP TABLE", -1, 0, "", "|", "IDX|STATE|STATE DESC|LOCAL IP|LOCAL PORT|REMOTE IP|REMOTE PORT")

Global $aTcpTable_BL = _WinAPI_GetExtendedTcpTable($TCP_TABLE_BASIC_LISTENER)
_ArrayDisplay($aTcpTable_BL, "Extended TCP TABLE - Listening only", -1, 0, "", "|", "IDX|STATE|STATE DESC|LOCAL IP|LOCAL PORT|REMOTE IP|REMOTE PORT")

Global $aTcpTable_PID = _WinAPI_GetExtendedTcpTable($TCP_TABLE_OWNER_PID_ALL)
_ArrayDisplay($aTcpTable_PID, "Extended TCP TABLE - PID included", -1, 0, "", "|", "IDX|STATE|STATE DESC|LOCAL IP|LOCAL PORT|REMOTE IP|REMOTE PORT|PID")


;~ Global $aTcpTable_Module = _WinAPI_GetExtendedTcpTable($TCP_TABLE_OWNER_MODULE_ALL)
;~ _ArrayDisplay($aTcpTable_Module, "Extended TCP TABLE - Module All", -1, 0, "", "|", "IDX|STATE|STATE DESC|LOCAL IP|LOCAL PORT|REMOTE IP|REMOTE PORT|PID|TIMESTAMP")




Func _WinAPI_GetTcpTable()
    ;funkey 2012.12.14
    Local Const $aConnState[12] = ["CLOSED", "LISTENING", "SYN_SENT", "SYN_RCVD", "ESTABLISHED", "FIN_WAIT1", _
            "FIN_WAIT2", "CLOSE_WAIT", "CLOSING", "LAST_ACK", "TIME_WAIT", "DELETE_TCB"]

    Local $tMIB_TCPTABLE = DllStructCreate("dword[6]")
    Local $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", 0, "BOOL", True)
    Local $dwSize = $aRet[2]
    $tMIB_TCPTABLE = DllStructCreate("DWORD[" & $dwSize / 4 & "]")

    $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", $dwSize, "BOOL", True)
    If $aRet[0] <> 0 Then Return SetError(1)
    Local $iNumEntries = DllStructGetData($tMIB_TCPTABLE, 1, 1)
    Local $aRes[$iNumEntries][6]

    For $i = 0 To $iNumEntries - 1
        $aRes[$i][0] = DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 0)
        $aRes[$i][1] = $aConnState[$aRes[$i][0] - 1]
        $aRet = DllCall("ws2_32.dll", "str", "inet_ntoa", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 1)) ; local IP / translate
        $aRes[$i][2] = $aRet[0]
        $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 2)) ; local port / translate
        $aRes[$i][3] = $aRet[0]
        $aRet = DllCall("ws2_32.dll", "str", "inet_ntoa", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 3)) ; remote IP / translate
        $aRes[$i][4] = $aRet[0]
        If $aRes[$i][0] <= 2 Then
            $aRes[$i][5] = 0
        Else
            $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 4)) ; remote port / translate
            $aRes[$i][5] = $aRet[0]
        EndIf
    Next

    Return $aRes
EndFunc   ;==>_WinAPI_GetTcpTable


Func _WinAPI_GetExtendedTcpTable($iTableClass)
    ;funkey 2012.12.14
    Local Const $aConnState[12] = ["CLOSED", "LISTENING", "SYN_SENT", "SYN_RCVD", "ESTABLISHED", "FIN_WAIT1", _
            "FIN_WAIT2", "CLOSE_WAIT", "CLOSING", "LAST_ACK", "TIME_WAIT", "DELETE_TCB"]

    Local Const $AF_INET = 2

    Local $tTCPTABLE = 0, $iLoop = 0
    Switch Floor($iTableClass / 3)
        Case 0
            $tTCPTABLE = DllStructCreate("DWORD[6]")
            $iLoop = 5
        Case 1
            $tTCPTABLE = DllStructCreate("DWORD[7]")
            $iLoop = 6
        Case 2
            $tTCPTABLE = DllStructCreate("DWORD[7];INT64;UINT64[16]")
            $iLoop = 40
    EndSwitch

    Local $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetExtendedTcpTable", "struct*", $tTCPTABLE, "DWORD*", 0, "BOOL", True, "ULONG", $AF_INET, "INT", $iTableClass, "ULONG", 0)
    Local $dwSize = $aRet[2]
    $tTCPTABLE = DllStructCreate("DWORD[" & $dwSize / 4 & "]")
    $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetExtendedTcpTable", "struct*", $tTCPTABLE, "DWORD*", $dwSize, "BOOL", True, "ULONG", $AF_INET, "INT", $iTableClass, "ULONG", 0)
    If $aRet[0] <> 0 Then Return SetError(1)
    Local $iNumEntries = DllStructGetData($tTCPTABLE, 1, 1)
    If $iLoop = 40 Then
        Local $aRes[$iNumEntries][8]
    Else
        Local $aRes[$iNumEntries][$iLoop + 1]
    EndIf

    Local $iOffset = 2, $tTemp = 0
    If $iLoop = 40 Then $iOffset = 3
    For $i = 0 To $iNumEntries - 1
        $aRes[$i][0] = DllStructGetData($tTCPTABLE, 1, $iOffset + $i * $iLoop + 0)
        $aRes[$i][1] = $aConnState[$aRes[$i][0] - 1]
        $aRet = DllCall("ws2_32.dll", "str", "inet_ntoa", "uint", DllStructGetData($tTCPTABLE, 1, $iOffset + $i * $iLoop + 1)) ; local IP
        $aRes[$i][2] = $aRet[0]
        $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tTCPTABLE, 1, $iOffset + $i * $iLoop + 2)) ; local port
        $aRes[$i][3] = $aRet[0]
        $aRet = DllCall("ws2_32.dll", "str", "inet_ntoa", "uint", DllStructGetData($tTCPTABLE, 1, $iOffset + $i * $iLoop + 3)) ; remote IP
        $aRes[$i][4] = $aRet[0]
        If $aRes[$i][0] <= 2 Then
            $aRes[$i][5] = 0
        Else
            $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tTCPTABLE, 1, $iOffset + $i * $iLoop + 4)) ; remote port
            $aRes[$i][5] = $aRet[0]
        EndIf
        If $iLoop = 6 Or $iLoop = 40 Then
            $aRes[$i][6] = DllStructGetData($tTCPTABLE, 1, $iOffset + $i * $iLoop + 5)
        EndIf
        If $iLoop = 40 Then
            $tTemp = DllStructCreate("word[8]", DllStructGetPtr($tTCPTABLE, 1) + (($iOffset + $i * $iLoop + 6) * 4))
            $aRes[$i][7] = StringFormat("Date: %i.%i.%i", DllStructGetData($tTemp, 1, 1), DllStructGetData($tTemp, 1, 2), DllStructGetData($tTemp, 1, 4))
        EndIf
    Next

    Return $aRes
EndFunc   ;==>_WinAPI_GetExtendedTcpTable
发表于 2014-4-14 19:37:54 | 显示全部楼层
这个包含该函数

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-23 22:08 , Processed in 0.073432 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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