Faced such a problem, I want to pull out only the name of the Internet connection, I do this:

NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in interfaces) { Console.WriteLine (adapter.Name); } 

And I get as many as 3 lines, the second is the real name of the connection, I only need it. Here is what data comes in:

 Подключение по локальной сети 12 Интертелеком MS TCP Loopback interface 

You need to get only the name, i.e. Intertelecom help please!

    2 answers 2

    Use the OperationalStatus property.

    Indicates the operational status of the network interface.

    Up The network interface works and can transmit data packets.

      And I would pay attention to the NetworkInterfaceType property. At a minimum, loops should be excluded from the entire set of network interfaces ( NetworkInterfaceType.Loopback ). But best of all, look at the values ​​of this property for all interfaces and select the ones you need.

      • Alas, it is possible that a platform-independent solution is not found. But platform-dependent ... Find through which interface the default route goes (or analyze the output of the route print command, or by means of winapi) and output it. Since this is about "connecting to the Internet", it should work. - alexlz