LabRat
LabRat

Reputation: 2014

Get IP addresses currently using designated port number

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?

Upvotes: 0

Views: 413

Answers (1)

RobertBaron
RobertBaron

Reputation: 2854

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

Upvotes: 1

Related Questions