How can I get all active TCP connections using the .NET Framework (without unmanaged PE import!)?

How can I get all active TCP connections using the .NET Framework (without unmanaged PE import!)?

I get socket programming and want to check this out. In my research, I found solutions by importing an unmanaged DLL file that does not interest me.

+8
c # sockets
source share
1 answer

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)

+19
source share

All Articles