We are using the following code for retrieving active MAC address of a windows pc.
private static string macId()
{
return identifier(\"Win32_NetworkAdapt
Well, I wouldn't bet all my money on the order in which NetworkInterface class lists NetworkInterfaces. My mainboard has 2 adapters and the order seems to switch every time I reboot.
So here is a suggestion, which worked for me (BTW : credits goes probably to another awesome stackoverflow contributer, ty) :
public static string GetMACAddress()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
//for each j you can get the MAC
PhysicalAddress address = nics[0].GetPhysicalAddress();
byte[] bytes = address.GetAddressBytes();
string macAddress = "";
for (int i = 0; i < bytes.Length; i++)
{
// Format the physical address in hexadecimal.
macAddress += bytes[i].ToString("X2");
// Insert a hyphen after each byte, unless we are at the end of the address.
if (i != bytes.Length - 1)
{
macAddress += "-";
}
}
return macAddress;
}