0

I have a simple TCP client-server setup made in vb.net. I would like to know if it is possible to return all the IP addresses currently using the designated port number, and how would I go about it?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
LabRat
  • 1,996
  • 11
  • 56
  • 91
  • See [How can I get all the the active TCP connections using .NET Framework (no unmanaged PE import!)?](https://stackoverflow.com/questions/13806435/how-can-i-get-all-the-the-active-tcp-connections-using-net-framework-no-unmana). – RobertBaron Jul 13 '19 at 10:40

1 Answers1

1

Here is the VB.NET solution translated from IPGlobal​Properties.​Get​Active​Tcp​Connections Method.

Imports System.Net.NetworkInformation

Module Module1

    Sub Main()
        ShowActiveTcpConnections()
    End Sub

    Public Sub ShowActiveTcpConnections()
        Debug.WriteLine("Active TCP Connections")
        Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties
        Dim connections() As TcpConnectionInformation = properties.GetActiveTcpConnections
        For Each c As TcpConnectionInformation In connections
            Debug.WriteLine("{0} <==> {1}", c.LocalEndPoint.ToString, c.RemoteEndPoint.ToString)
        Next
    End Sub

End Module

Example of output:

Active TCP Connections
127.0.0.1:1028 <==> 127.0.0.1:5354
127.0.0.1:1029 <==> 127.0.0.1:5354
127.0.0.1:1055 <==> 127.0.0.1:27015
127.0.0.1:1069 <==> 127.0.0.1:27015
127.0.0.1:1071 <==> 127.0.0.1:27015
127.0.0.1:1080 <==> 127.0.0.1:27015
127.0.0.1:1081 <==> 127.0.0.1:5354
127.0.0.1:1082 <==> 127.0.0.1:5354
127.0.0.1:1084 <==> 127.0.0.1:1085
127.0.0.1:1085 <==> 127.0.0.1:1084
127.0.0.1:1154 <==> 127.0.0.1:27015
127.0.0.1:5354 <==> 127.0.0.1:1028
RobertBaron
  • 2,817
  • 1
  • 12
  • 19