IPGlobalProperties.GetActiveTcpConnections Method

Definition

Returns information about the Internet Protocol version 4 (IPv4) and IPv6 Transmission Control Protocol (TCP) connections on the local computer.

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
public abstract System.Net.NetworkInformation.TcpConnectionInformation[] GetActiveTcpConnections();
C#
public abstract System.Net.NetworkInformation.TcpConnectionInformation[] GetActiveTcpConnections();

Returns

A TcpConnectionInformation array that contains objects that describe the active TCP connections, or an empty array if no active TCP connections are detected.

Attributes

Exceptions

The Win32 function GetTcpTable failed.

Examples

The following example displays endpoint information for active TCP connections.

C#
public static void ShowActiveTcpConnections()
{
           Console.WriteLine("Active TCP Connections");
           IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
           TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
           foreach (TcpConnectionInformation c in connections)
           {
               Console.WriteLine("{0} <==> {1}",
                   c.LocalEndPoint.ToString(),
                   c.RemoteEndPoint.ToString());
           }
}

Remarks

The objects returned by this method include connections in all TCP states except the Listen state. You can check the state of a connection by calling State.

The TCP protocol is defined in IETF RFC 793. Note that the objects returned by this method reflect the connections as of the time the array is created. This information is not updated dynamically.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1