I am surprised at the number of users who tell me that this cannot be done with pure managed code ... For future users who are wondering about this, find the details from the answer that works great for me:
//Don't forget this: using System.Net.NetworkInformation; 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()); } }
And call ShowActiveTcpConnections() to list it, amazing and beautiful.
Source: IPGlobalProperties.GetActiveTcpConnections Method (MSDN)
Rollroll
source share