I make a console application that should check the connection to a specific IP and perform certain actions. How to monitor such a connection? Here is a list of all outgoing, how to filter and leave only one?
static void ListAvailableTCPPort(ref ArrayList usedPort) { IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections(); IEnumerator myEnum = tcpConnInfoArray.GetEnumerator(); while (myEnum.MoveNext()) { TcpConnectionInformation TCPInfo = (TcpConnectionInformation)myEnum.Current; Console.WriteLine("{0}", TCPInfo.RemoteEndPoint); usedPort.Add(TCPInfo.LocalEndPoint.Port); } } public static void Main() { ArrayList usedPorts = new ArrayList(); ListAvailableTCPPort(ref usedPorts); Console.ReadKey(); }
Console.WriteLine("{0}", TCPInfo.RemoteEndPoint);
Corrected data output only to the final SP: port. I want to choose from this list only one connection (for example: 127.0.0.1 LI3937) - Elizaveta