#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()