locked
Getting Active Connections in C#

    Question

  • How can i retrive the status of current tcp and udp connection without usign P/Invoke (Win32Api - IpHelperApi dll) in C sharp?
    Thursday, July 31, 2008 12:25 PM

Answers

  • Use the System.Net.NetworkInformation namespace.  There is a class called IPGlobalProperties.  Use the methods off ip global properties to get the information you need.

                IPGlobalProperties ipGlobal = IPGlobalProperties.GetIPGlobalProperties();
                Array.ForEach<TcpConnectionInformation>(ipGlobal.GetActiveTcpConnections(),
                    delegate(TcpConnectionInformation i) { Console.WriteLine("{0} {1} {2}",i.LocalEndPoint,i.RemoteEndPoint,i.State); }
                );
    • Marked as answer by jack 321 Tuesday, August 05, 2008 3:43 AM
    Friday, August 01, 2008 4:05 AM

All replies

  • I don't know exactly what you need but much information can be retrieved using WMI.
    Thursday, July 31, 2008 1:18 PM
  • Use the System.Net.NetworkInformation namespace.  There is a class called IPGlobalProperties.  Use the methods off ip global properties to get the information you need.

                IPGlobalProperties ipGlobal = IPGlobalProperties.GetIPGlobalProperties();
                Array.ForEach<TcpConnectionInformation>(ipGlobal.GetActiveTcpConnections(),
                    delegate(TcpConnectionInformation i) { Console.WriteLine("{0} {1} {2}",i.LocalEndPoint,i.RemoteEndPoint,i.State); }
                );
    • Marked as answer by jack 321 Tuesday, August 05, 2008 3:43 AM
    Friday, August 01, 2008 4:05 AM