找回密码
 加入
搜索
查看: 1812|回复: 6

关于AU3获取指定IP的连接状态

[复制链接]
发表于 2009-6-29 18:01:30 | 显示全部楼层 |阅读模式
本帖最后由 chengjinn 于 2009-8-22 14:51 编辑

想问下。AU3能不能实现。。获取指定IP与本机的连接状态。并返回!!!
如  219.133.60.173:https   ESTABLISHED
 楼主| 发表于 2009-6-29 18:01:49 | 显示全部楼层
沙发自已坐。。在线等回答!
发表于 2009-6-29 22:48:02 | 显示全部楼层
不能返回指定的,但能返回所有的。以下代码相当于执行'netstat -anp tcp'。
有了以下代码,返回指定的连接状态就根本不是问题,楼主自己改。
#include <Array.au3>

$aTable = _GetTcpTable()
_Arraydisplay($aTable)

Func _GetTcpTable()
        Local $iResult, $tBuffer, $pBuffer, $tNum, $tagTable, $tTable, $aResult[1][5] = [[0]], $sData

        $iResult = DllCall("iphlpapi.dll", "dword", "GetTcpTable", _
                        "ptr", 0, "dword*", 0, "int", 1)
        $tBuffer = DllStructCreate("byte[" & $iResult[2] & "]")
        $pBuffer = DllStructGetPtr($tBuffer)
        $iResult = DllCall("iphlpapi.dll", "dword", "GetTcpTable", _
                        "ptr", $pBuffer, "dword*", $iResult[2], "int", 1)

        $tNum = DllStructCreate("int", $pBuffer)
        $aResult[0][0] = DllStructGetData($tNum, 1)
        Redim $aResult[$aResult[0][0] + 1][5]
        For $i = 1 to $aResult[0][0]
                $tagTable &= ";dword[5]"
        Next

        $tTable = DllStructCreate("dword" & $tagTable, $pBuffer)
        For $i = 1 to $aResult[0][0]
                For $f = 1 to 5
                        $sData = DllStructGetData($tTable, $i + 1, $f)
                        Switch $f
                        Case 2, 4
                                $aResult[$i][$f - 1] = _inet_ntoa($sData)
                        Case 3, 5
                                $aResult[$i][$f - 1] = _ntohs($sData)
                        Case Else
                                $aResult[$i][$f - 1] = _FormatState($sData)
                        EndSwitch
                Next
        Next
        $tNum = 0
        $tTable = 0
        $tBuffer = 0
        Return SetError($iResult[0], 0, $aResult)
EndFunc        ;==>_GetTcpTable()

Func _inet_ntoa($iAddr)
        Local $sAddr
        $sAddr = DllCall("Ws2_32.dll", "str", "inet_ntoa", "long", $iAddr)
        Return $sAddr[0]
EndFunc        ;==>_inet_ntoa()

Func _ntohs($u_short)
        Local $iResult
        $iResult = DllCall("Ws2_32.dll", "ushort", "ntohs", "ushort", $u_short)
        Return $iResult[0]
EndFunc        ;==>_ntohs()

Func _FormatState($iState)
        Local $aState[12] = ["CLOSED", "LISTENING", "SYN_SENT", "SYN_RECEIVED", "ESTABLISHED", "FIN-WAIT_1", "FIN-WAIT_2", "CLOSE_WAIT", "CLOSING", "LAST_ACK", "TIME_WAIT", "DELETE_TCB"]
        Return $aState[$iState - 1]
EndFunc        ;==>_FormatState()
发表于 2009-7-4 12:12:29 | 显示全部楼层
学习一下,谢谢
发表于 2009-7-4 12:22:25 | 显示全部楼层
看看+学习...
发表于 2011-12-20 01:54:44 | 显示全部楼层
留下脚印。。代表我曾经来过!
发表于 2012-1-25 23:29:18 | 显示全部楼层
认真学习了!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 23:38 , Processed in 0.224809 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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