Many network adapters at machine, need to find one that is used for traffic in Windows (from .net)

Posted by viko on Stack Overflow See other posts from Stack Overflow or by viko
Published on 2011-03-01T07:23:16Z Indexed on 2011/03/01 7:24 UTC
Read the original article Hit count: 84

My application use Web-service. I'm control from what workstation was request and for this send MAC-Address how parameter of all methods. But then I start testing application in real, I found workstations which have many network adapters - Ethernet, Wireless, Bluetooth. When I get MAC-address using next code:

var networkAdapters = NetworkInterface.GetAllNetworkInterfaces();
if (networkAdapters == null || networkAdapters.Length == 0)
    return string.Empty;

string address = string.Empty;

foreach (var adapter in networkAdapters)
{
    var a = adapter.GetPhysicalAddress();
    if (a != null && a.ToString() != string.Empty)
    {
        address = a.ToString();
        break;
    }
}
return address;

Sometimes Web-service receive from workstation different MAC-Addresses, but I want get always only one MAC-address. Please, help me.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about network-programming