Option Explicit
#Const ISDEBUG = False
Public Declare Function GetTcpTable Lib "iphlpapi.dll" (ByRef pTcpTable As MIB_TCPTABLE, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef pDest As Any, ByRef pSource As Any, ByVal Length As Long)
Private Type MIB_TCPROW ' TCP row
dwState As Long
dwLocalAddr As Long ' Local IP
dwLocalPort As Long ' Local port
dwRemoteAddr As Long ' Remote IP
dwRemotePort As Long ' Remote port
End Type
Private Type MIB_TCPTABLE ' TCP table
dwNum_Of_Entries As Long ' link counts
TCP_Table(500) As MIB_TCPROW ' TCP rows
End Type
Dim Last_Num_Of_Entries As Long
Dim TCP1 As MIB_TCPTABLE
'state
Dim state As Boolean
Public Sub Main()
Dim i As Long
Dim Return1 As Long
Dim Ip_Buf(1 To 4) As Byte
Dim ConnState, LocalIp, LocalPort, RemoteIp, RemotePort
Return1 = GetTcpTable(TCP1, Len(TCP1), 1) ' get TCP link table
Last_Num_Of_Entries = TCP1.dwNum_Of_Entries
If Return1 = 0 Then
If Last_Num_Of_Entries <> 0 Then
On Error GoTo ...
For i = 0 To TCP1.dwNum_Of_Entries - 1
CopyMemory Ip_Buf(1), TCP1.TCP_Table(i).dwRemoteAddr, 4
RemoteIp = CStr(Ip_Buf(1)) + "." + CStr(Ip_Buf(2)) + "." + CStr(Ip_Buf(3)) + "." + CStr(Ip_Buf(4))
'...
Next
End If
Else
'...
End If
End Sub