关于AU3获取指定IP的连接状态
本帖最后由 chengjinn 于 2009-8-22 14:51 编辑想问下。AU3能不能实现。。获取指定IP与本机的连接状态。并返回!!!
如219.133.60.173:https ESTABLISHED 沙发自已坐。。在线等回答! 不能返回指定的,但能返回所有的。以下代码相当于执行'netstat -anp tcp'。
有了以下代码,返回指定的连接状态就根本不是问题,楼主自己改。#include <Array.au3>
$aTable = _GetTcpTable()
_Arraydisplay($aTable)
Func _GetTcpTable()
Local $iResult, $tBuffer, $pBuffer, $tNum, $tagTable, $tTable, $aResult = [], $sData
$iResult = DllCall("iphlpapi.dll", "dword", "GetTcpTable", _
"ptr", 0, "dword*", 0, "int", 1)
$tBuffer = DllStructCreate("byte[" & $iResult & "]")
$pBuffer = DllStructGetPtr($tBuffer)
$iResult = DllCall("iphlpapi.dll", "dword", "GetTcpTable", _
"ptr", $pBuffer, "dword*", $iResult, "int", 1)
$tNum = DllStructCreate("int", $pBuffer)
$aResult = DllStructGetData($tNum, 1)
Redim $aResult[$aResult + 1]
For $i = 1 to $aResult
$tagTable &= ";dword"
Next
$tTable = DllStructCreate("dword" & $tagTable, $pBuffer)
For $i = 1 to $aResult
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, $aResult)
EndFunc ;==>_GetTcpTable()
Func _inet_ntoa($iAddr)
Local $sAddr
$sAddr = DllCall("Ws2_32.dll", "str", "inet_ntoa", "long", $iAddr)
Return $sAddr
EndFunc ;==>_inet_ntoa()
Func _ntohs($u_short)
Local $iResult
$iResult = DllCall("Ws2_32.dll", "ushort", "ntohs", "ushort", $u_short)
Return $iResult
EndFunc ;==>_ntohs()
Func _FormatState($iState)
Local $aState = ["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() 学习一下,谢谢 看看+学习... 留下脚印。。代表我曾经来过! 认真学习了!
页:
[1]