首页 > 解决方案 > 如何获取客户端的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;
            }
        }
    }

标签: c#asp.netmac-address

解决方案


是的。这类似于要求从电话中获取电话的 IMSI - 不可能,您拨打电话号码,其余的是实现细节。MAC 地址几乎不会传输超过一个以太网域(下一个交换机/路由器)。它们不是 IP 协议层的一部分。因此,您无法从 http 请求中获取它们,这最终是一个 TCP,因此是一个 IP 连接。您必须在客户端上执行(C#,而不是 javascript)代码才能获得本地 MAC 地址 - 即复数,可能有多个(如:2 个本地网卡,一个无线适配器 = 3 个 MAC 地址) .


推荐阅读