TCP & UDP connection table
Posted: Sat Sep 02, 2006 12:24 pm
Code updated For 5.20+
progress for display of all open TCP and UDP endpoints.
progress for display of all open TCP and UDP endpoints.
Code: Select all
Dim TCPstate.s(15)
For k = 1 To 15
TCPstate(k) = StringField("Closed|Listening|SYN Sent|SYN Received|Established|Waiting For FIN|Waiting For FIN|Waiting For Close|Closing|Last ACK|Time Wait|TCB deleted", k, "|")
Next
Structure MIB_TCPROW
dwStats.l
dwLocalAddr.l
dwLocalPort.l
dwRemoteAddr.l
dwRemotePort.l
EndStructure
Structure MIB_TCPTABLE
dwNumEntries.l
table.MIB_TCPROW[2048]
EndStructure
Structure MIB_UDPROW
dwLocalAddr.l
dwLocalPort.l
EndStructure
Structure MIB_UDPTABLE
dwNumEntries.l
table.MIB_UDPROW[2048]
EndStructure
Procedure.s long2ip(longIP.l)
fourth.l = longIP / 16777216
longIP = longIP % 16777216
third.l = longIP / 65536
longIP = longIP % 65536
second.l = longIP / 256
first.l = longIP % 256
ProcedureReturn(Str(first) + "." + Str(second) + "." + Str(third) + "." + Str(fourth))
EndProcedure
dwSize = $0
If GetTcpTable_(@tcpTable.MIB_TCPTABLE, @dwSize, #True)
If GetTcpTable_(@tcpTable.MIB_TCPTABLE, @dwSize, #True) = #NO_ERROR
For cnt = 0 To tcpTable\dwNumEntries - 1
Debug("type: TCP")
Debug("state: " + TCPstate (tcpTable\table[cnt]\dwStats))
Debug("local IP: " + long2ip(tcpTable\table[cnt]\dwLocalAddr))
Debug("local port: " + Str(htons_(tcpTable\table[cnt]\dwLocalPort)))
Debug("remote IP: " + long2ip(tcpTable\table[cnt]\dwRemoteAddr))
Debug("remote port: " + Str(htons_(tcpTable\table[cnt]\dwRemotePort)))
Debug("")
Next
EndIf
EndIf
dwSize = $0
If GetUdpTable_(@udpTable.MIB_UDPTABLE, @dwSize, #True)
If GetUdpTable_(@udpTable.MIB_UDPTABLE, @dwSize, #True) = #NO_ERROR
For cnt = 0 To udpTable\dwNumEntries - 1
Debug("type UDP")
Debug("local IP: " + long2ip (udpTable\table[cnt]\dwLocalAddr))
Debug("local port: " + Str(htons_ (udpTable\table[cnt]\dwLocalPort)))
Debug("")
Next
EndIf
EndIf
End