J
Jole
How to get it, the one which is in use currently?
Thaks!
Thaks!
How to get it, the one which is in use currently?
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.
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
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...
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 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
You may get more info with WMI selecting fromThanks a lot, that works fine... Now I must figure out how toNetworkInterface[] 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.
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...).
Win32_NetworkAdapterConfiguration, but I can still not see a default
property.
Arne
Why not just report the stats for all adapters? Or give the user the choice of what adapter to report for?
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