IMPORTANT EDIT: Back again on this subject. As you said there should be no default NIC, I\'m trying to understand if there is a way to detect all the NICs t
You can use the WMI class Win32_NetworkAdapter to enumerate all the adapters and it has an Index
property which might mean that the one with 0 or 1 as the Index
is the default one, or one of the other properties might help to find the default one.
Something like this maybe:
Edit: Fixed broken code (this is at least more likely to work). But following what abatishchev said I think you might need to use Win32_NetworkAdapterConfiguration.IPConnectionMetric
to find the default adapter...
ManagementClass mc = new ManagementClass("Win32_NetworkAdapter");
foreach (ManagementObject mo in mc.GetInstances())
{
int index = Convert.ToInt32(mo["Index"]);
string name = mo["NetConnectionID"] as string;
if (!string.IsNullOrEmpty(name))
textBox1.Text += name + Environment.NewLine;
}