如果机器上的某个虚拟适配器具有运行状态为Up,如何获取网络适配器的MAC地址。 [英] how to get MAC address of network adapter if some virtual adapter on the machine have operation status is Up.

查看:124
本文介绍了如果机器上的某个虚拟适配器具有运行状态为Up,如何获取网络适配器的MAC地址。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private string GetMACAddress()// ---------------------- retrive client MAC address

{

NetworkInterface [] nics = NetworkInterface.GetAllNetworkInterfaces();

String sMacAddress = string.Empty;

foreach(nics中的NetworkInterface适配器)

$



if(adapter.OperationalStatus == OperationalStatus.Up)

{

sMacAddress = adapter .GetPhysicalAddress()。ToString();

break;

}

}

返回sMacAddress;

}

private string GetMACAddress() //----------------------retrive client MAC address
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (NetworkInterface adapter in nics)
{

if (adapter.OperationalStatus==OperationalStatus.Up)
{
sMacAddress = adapter.GetPhysicalAddress().ToString();
break;
}
}
return sMacAddress;
}

推荐答案

您无法在ASP.NET应用程序中获取客户端MAC地址。



您发布的代码是获取SERVER上的接口,而不是客户端。 ASP.NET代码总是完全在服务器上运行,而不是客户端。



此外,MAC地址在客户端所在的网络之外没有意义。它不是全局唯一值,不能用于唯一标识客户端。
You can NOT get the client MAC address in an ASP.NET application.

The code you posted is getting the interfaces on the SERVER, not the client. ASP.NET code always runs entirely on the server, never the client.

Also, the MAC address is meaningless outside of the network the client is sitting on. It is NOT a globally unique value and cannot be used to identify a client uniquely.


这篇关于如果机器上的某个虚拟适配器具有运行状态为Up,如何获取网络适配器的MAC地址。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆