如何获取客户端mac地址 [英] how to get client mac address

查看:113
本文介绍了如何获取客户端mac地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
如何获取客户端mac地址?

  string  macAddresses =  ; 

foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddresses + = nic.GetPhysicalAddress()。ToString ();
break ;
}
}





这是我的代码。但是这段代码返回服务器的mac地址



请帮帮我!

解决方案

简短的回答是:否



无法使用JavaScript从客户端获取MAC地址,因为这会带来严重的安全风险。



唯一可以获得的唯一ID是IP地址,但这可能不是唯一的,因为用户的计算机可能在路由器后面进行NAT操作。



您可以在Java applet上使用ActiveX控件来获取客户端计算机的MAC地址,但这需要在客户端计算机上安装所选方法,并且永远不会成为获取MAC地址的故障安全方法。 / blockquote>

你不能。就这么简单。



您所拥有的代码只会提供服务器的MAC地址而不是客户端的MAC地址。由于网络的运作方式,没有可靠的方法来获取Web应用中的客户端MAC。你得到的最好的是最靠近网络服务器的路由器上的接口的MAC地址。



唯一可行的方法是客户是在与Web服务器相同的物理子网上,您必须使用ARP解析才能获得它。但是,就像我说的那样,它只有在客户端与服务器位于同一物理子网上时才有效。


hi how to get client mac address?

string macAddresses = "";

        foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
        {
            if (nic.OperationalStatus == OperationalStatus.Up)
            {
                macAddresses += nic.GetPhysicalAddress().ToString();
                break;
            }
        }



it is my code. but this code return server mac address

please help me!

解决方案

The short answer is: No

It is not possible to get the MAC address from the client using JavaScript as this will pose a serious security risk.

The only unique id you will be able to get is the IP address, but this will possibly not be unique as the user's machine might be NATed behind a router.

You could use an ActiveX control on Java applet to get the client machine's MAC address, but this would require installation of the chosen method on the client machine and will never be a fail-safe way of obtaining the MAC address.


You can't. Its that simple.

The code you have will only give you the MAC addresses of the server not the clients. There is no reliable way to get the MAC of clients in a web app because of how networking works. The best you're going to get is the MAC address of the interface on the router closest to the web server.

The only way it works is if the clients are on the same physical subnet as the web server and you have to use ARP resolution to get it. But, like I said, it only works if the clients are on the same physical subnet as your server.


这篇关于如何获取客户端mac地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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