Default network adater?

  • Thread starter Thread starter Jole
  • Start date Start date
How to get it, the one which is in use currently?

This code should list the NIC's:

NetworkInterface[] nics =
NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface nic in nics)
{
if(nic.GetPhysicalAddress().ToString().Length > 0 &&
nic.GetIPProperties().UnicastAddresses.Count > 0)
{
Console.WriteLine(nic.GetPhysicalAddress() + " " +
nic.GetIPProperties().UnicastAddresses[0].Address);
}
}

not that you can have multiple active net cards and
if you have multiple physical cards I think it is even most
common to have them all active.

Arne
 
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface nic in nics)
{
if(nic.GetPhysicalAddress().ToString().Length > 0 &&
nic.GetIPProperties().UnicastAddresses.Count > 0)
{
Console.WriteLine(nic.GetPhysicalAddress() + " " + nic.GetIPProperties().UnicastAddresses[0].Address);
}
}

not that you can have multiple active net cards and
if you have multiple physical cards I think it is even most
common to have them all active.

Arne


Thanks a lot, that works fine... Now I must figure out how to determine which is
default for network communication... for example in Network Connection Details (Win7)
i get informations about my defalt adapter (VIA Rhine II Compatibile...).
 
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface nic in nics)
{
if(nic.GetPhysicalAddress().ToString().Length > 0 &&
nic.GetIPProperties().UnicastAddresses.Count > 0)
{
Console.WriteLine(nic.GetPhysicalAddress() + " " +
nic.GetIPProperties().UnicastAddresses[0].Address);
}
}

not that you can have multiple active net cards and
if you have multiple physical cards I think it is even most
common to have them all active.

Thanks a lot, that works fine... Now I must figure out how to determine
which is
default for network communication... for example in Network Connection
Details (Win7)
i get informations about my defalt adapter (VIA Rhine II Compatibile...).

You may get more info with WMI selecting from
Win32_NetworkAdapterConfiguration, but I can still not
see a default property.

Arne
 
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface nic in nics)
{
if(nic.GetPhysicalAddress().ToString().Length > 0 &&
nic.GetIPProperties().UnicastAddresses.Count > 0)
{
Console.WriteLine(nic.GetPhysicalAddress() + " " +
nic.GetIPProperties().UnicastAddresses[0].Address);
}
}

not that you can have multiple active net cards and
if you have multiple physical cards I think it is even most
common to have them all active.

Thanks a lot, that works fine... Now I must figure out how to determine
which is
default for network communication... for example in Network Connection
Details (Win7)
i get informations about my defalt adapter (VIA Rhine II Compatibile...).

You may get more info with WMI selecting from
Win32_NetworkAdapterConfiguration, but I can still not
see a default property.

Arne

Now I was tried your code and my using PerformanceCounters and in both ways they
listed my defualt network adapter first. Also the same situation is on my second
computer...
 
On 24.10.2010 20:58, Arne Vajhøj wrote:

NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface nic in nics)
{
if(nic.GetPhysicalAddress().ToString().Length > 0 &&
nic.GetIPProperties().UnicastAddresses.Count > 0)
{
Console.WriteLine(nic.GetPhysicalAddress() + " " +
nic.GetIPProperties().UnicastAddresses[0].Address);
}
}

not that you can have multiple active net cards and
if you have multiple physical cards I think it is even most
common to have them all active.

Thanks a lot, that works fine... Now I must figure out how to determine
which is
default for network communication... for example in Network Connection
Details (Win7)
i get informations about my defalt adapter (VIA Rhine II
Compatibile...).

You may get more info with WMI selecting from
Win32_NetworkAdapterConfiguration, but I can still not
see a default property.
Now I was tried your code and my using PerformanceCounters and in both
ways they
listed my defualt network adapter first. Also the same situation is on
my second
computer...

I would be reluctant to consider that statistics good enough for
assuming it to always be the case.

Arne
 
On 24-10-2010 16:34, Jole wrote:

I would be reluctant to consider that statistics good enough for
assuming it to always be the case.

Arne

I agree with you but for now i dont have any better solution.
 
I think a better place to start would be to consider _why_ you are trying to get this information in the first place.
There isn't really a single "default" network adapter. The network protocol implementations select an appropriate
adapter depending on the protocol and destination of the specific network data being sent.

So, since there's no such thing as the "default" network adapter, what information are you _really_ trying to get, and
why do you believe that information to be useful? What is it that you are planning to do with the information?

Pete

I need that information for getting current up/down kb's using performance counters.
PC need instance name of network adapter... Or there si better solution?!
 
Hello Arne,
NetworkInterface[] nics =
NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface nic in nics)
{
if(nic.GetPhysicalAddress().ToString().Length > 0 &&
nic.GetIPProperties().UnicastAddresses.Count > 0)
{
Console.WriteLine(nic.GetPhysicalAddress() + " " +
nic.GetIPProperties().UnicastAddresses[0].Address);
}
}
not that you can have multiple active net cards and
if you have multiple physical cards I think it is even most
common to have them all active.
Thanks a lot, that works fine... Now I must figure out how to
determine
which is
default for network communication... for example in Network
Connection
Details (Win7)
i get informations about my defalt adapter (VIA Rhine II
Compatibile...).
You may get more info with WMI selecting from
Win32_NetworkAdapterConfiguration, but I can still not see a default
property.

Arne

There's no "Default", but he could filter on IPEnabled.

Karl
http://unlockpowershell.wordpress.com/
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
 
Why not just report the stats for all adapters? Or give the user the choice of what adapter to report for?

hm... i trying to avoid this option when user can chose adapter... The first idea that you mention is very
good. Do you have any example for that?
 
Sorry, I don't understand the question. Arne's already posted code you can use to enumerate the adapters. With that,
can't you just get the information you want from each adapter and report it?

Pete

It doesen't matter any more, i've found solution...
 
Back
Top