List active tcp connections

We are going to use two classes to retrieve network connections, IPGlobalProperties and TcpConnectionInformation.

You will need a ListView control with two columns, one for local endpoint and another one for remote endpoint.

private void ListActiveTcpConnections()
{
	IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
	TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
	foreach (TcpConnectionInformation c in connections)
	{
		listView1.Items.Add(new ListViewItem(new String[]{c.LocalEndPoint.ToString(), 
                      c.RemoteEndPoint.ToString()}));
	}
}
Categories: C# Tags: , , ,
%d bloggers like this: