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
2009-03-31 15:12:06
+6
A:
using System.Net.NetworkInformation
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpInfoList = properties.GetActiveTcpConnections();
Jimmy
2009-03-31 15:13:02
Good solution... I wasn't actually aware there was a simple managed call to get such information.
Noldorin
2009-03-31 15:14:59
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
2009-03-31 15:15:50