Dim pdwSize As Integer
Dim iRetVal As Integer
Dim i As Integer
Dim TcpTableRow As MIB_TCPROW
Dim pStructPointer As IntPtr = IntPtr.Zero
Dim iNumberOfStructures As Integer
Form1.dgvtcp.Rows.Clear()
iRetVal = GetTcpTable(pStructPointer, pdwSize, 0)
pStructPointer = Marshal.AllocHGlobal(pdwSize)
iRetVal = GetTcpTable(pStructPointer, pdwSize, 0)
iNumberOfStructures = Math.Ceiling((pdwSize - 4) / Marshal.SizeOf(GetType(MIB_TCPROW)))
For i = 0 To iNumberOfStructures - 1
Dim pStructPointerTemp As IntPtr = New IntPtr(pStructPointer.ToInt32() + 4 + (i * Marshal.SizeOf(GetType(MIB_TCPROW))))
TcpTableRow = New MIB_TCPROW()
With TcpTableRow
.dwLocalAddr = 0
.dwState = 0
.dwLocalPort = 0
.dwRemoteAddr = 0
.dwRemotePort = 0
End With
'Marshal.PtrToStructure(pStructPointerTemp, TcpTableRow)
TcpTableRow = CType(Marshal.PtrToStructure(pStructPointerTemp, GetType(MIB_TCPROW)), MIB_TCPROW)
' Process each MIB_TCPROW here
With TcpTableRow
'Aqui desconecto la ip que este conectado a mi
If GetIpFromLong(.dwRemoteAddr).ToString = "Aqui La Ip" Then
.dwState = 12
Try
SetTcpEntry(TcpTableRow)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Exit For
End If
End With
Next
Marshal.FreeHGlobal(pStructPointer)
Probado en Windows 8.1