C#获取 mac
public static String getLocalMacAddress()
{//没有缓存的地址,则查询
String mac_s = “”;
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
if (nics == null || nics.Length < 1)
{
return mac_s;
}
try
{
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties properties = adapter.GetIPProperties(); // .GetIPInterfaceProperties();
string Description = adapter.Description;//接口的描述
string NetworkInterfaceType = adapter.NetworkInterfaceType.ToString();//获取接口类型
PhysicalAddress address = adapter.GetPhysicalAddress();//返回MAC地址
if (NetworkInterfaceType != "Loopback" && NetworkInterfaceType == "Ethernet")
mac_s= adapter.GetPhysicalAddress().ToString();
}