c# - 如何获取客户端的MAC地址?
问题描述
我正在尝试获取客户端 PC 的 MAC 地址,但它显示了托管我的项目的 IIS 服务器的 MAC 地址。
protected void Page_Load(object sender, EventArgs e)
{
NetworkInterface[] anics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in anics)
{
if (amacaddress == String.Empty)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
amacaddress = adapter.GetPhysicalAddress().ToString();
lblname.Visible = true;
string ip = Request.UserHostAddress;
lblname.Text = "MAC Address is :- " + amacaddress + " "+ ip;
}
}
}
解决方案
是的。这类似于要求从电话中获取电话的 IMSI - 不可能,您拨打电话号码,其余的是实现细节。MAC 地址几乎不会传输超过一个以太网域(下一个交换机/路由器)。它们不是 IP 协议层的一部分。因此,您无法从 http 请求中获取它们,这最终是一个 TCP,因此是一个 IP 连接。您必须在客户端上执行(C#,而不是 javascript)代码才能获得本地 MAC 地址 - 即复数,可能有多个(如:2 个本地网卡,一个无线适配器 = 3 个 MAC 地址) .
推荐阅读
- powershell - 如何使用 powershell 从服务器获取数据库备份路径?
- php - 无法在 000webhost 中使用会话变量
- php - 下载图片虽然.php - Wordpress
- python - Python 中的定义方法
- java - 为什么 ObjectOutputStream 用 DataOutputStream 写入 14 个字节而不是 8 个字节?
- java - 将现有活动添加到 TabActivity Android
- .net - vb.net中的货币值计算错误
- debugging - 调试 webOS TV 服务
- r - 在R中的列表中查找最接近的值
- java - Spring Boot 多缓存框架使用缓存解析器