views:

949

answers:

3

Given a list of IP addresses how do I programmatically check if the local machine still has active TCP connections to these IP Addresses? I am using C#.

A: 

Call GetExtendedTcpTable and check through the list for your target addresses

Stuart Dunkeld
+6  A: 
using System.Net.NetworkInformation    

IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpInfoList = properties.GetActiveTcpConnections();
Jimmy
Good solution... I wasn't actually aware there was a simple managed call to get such information.
Noldorin
A: 

I do not understand question exactly, but in case if you have list of addresses with a software that listen on some ports, try to connect there using eg. Socket class:

Socket m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
m_Socket.Connect(serverEndPoint);

and eventually try to catch an exception...

If you have connection that are already made in you code you can check m_Socket.Connected property..

bezieur