Best way to check if TCP connection is active

Given the list of IP addresses, how can I programmatically check if there are active TCP connections to these IP addresses on the local computer? I am using C #.

+4
source share
3 answers
using System.Net.NetworkInformation IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpInfoList = properties.GetActiveTcpConnections(); 
+6
source

Call GetExtendedTcpTable and check the list for destination addresses

0
source

I don’t understand the question exactly, but if you have a list of addresses with software that listens on some ports, try connecting there using, for example. Socket Class:

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

and eventually try to catch the exception ...

If you have a connection that is already made in your code, you can check the m_Socket.Connected .. property.

0
source

All Articles