I am writing a piece of software in C# using .NET 2 which detects whether there is an active ethernet connection on the Windows machine.
It is important that it knows that it is ethernet rather than WiFi as the program will behave differently depending on whether sending data with a WebClient is going over WiFi or Ethernet.
I have tried using System.Net.NetworkInformation.NetworkInterfaceType but this seems to report ‘Ethernet’ for a lot of WiFi cards.
Any suggestions will be much appreciated.
According to this MSDN page about the
NetworkInterface.NetworkInterfaceTypeproperty,So deterministically you may be SOL.
However, you may be able to perform some heuristics on the available network connections, to determine if they are WiFi or cable. These might include ping response/latency times taken over many iterations, etc.
Also, the speed of the adapter might be used as a hint. For my WiFi adapter the speed is always shown as “54000000” (e.g. 54 mbs). Since there is a set of common WiFi speeds, this could be helpful.
Perhaps the following code might get you started: