Hi,
following is the code-
returns the NIC with the fastest speed that also has a valid Mac Address.
private string GetMacAddress()
{
const int MIN_MAC_ADDR_LENGTH = 12;
string macAddress = "";
long maxSpeed=-1;
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
log.Debug("Found MAC Address: " + nic.GetPhysicalAddress().ToString() + " Type: " + nic.NetworkInterfaceType );
string tempMac = nic.GetPhysicalAddress().ToString();
if (nic.Speed > maxSpeed && !String.IsNullOrEmpty(tempMac) && tempMac.Length >= MIN_MAC_ADDR_LENGTH )
{
log.Debug("New Max Speed = " + nic.Speed + ", MAC: " + tempMac );
maxSpeed = nic.Speed;
macAddress = tempMac;
}
}
return macAddress;
}
Just returns the first one.
private string GetMacAddress()
{
string macAddresses = "";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddresses += nic.GetPhysicalAddress().ToString();
break;
}
}
return macAddresses;
}