简体   繁体   English

如何在JAVA中从客户端计算机获取MAC地址?

[英]How to fetch MAC Address from client machine in JAVA?

I am creating an website for that I need to fetch client's MAC address to identify the client. 我正在创建一个网站,我需要获取客户端的MAC地址以标识客户端。 I have tried with the applets, but it was not fruitful. 我尝试过使用applet,但效果不佳。 Please help. 请帮忙。

Using NetworkInterface only is an incomplete answer. 仅使用NetworkInterface是不完整的答案。 It would work if the goal was to get the SERVERS mac-address. 如果目标是获取SERVERS MAC地址,则它将起作用。 The poster clearly states that he wants the CLIENTS mac-address. 海报清楚地表明,他想要CLIENTS mac-address。

The way to accomplish this is either through an applet or through an ActiveX plugin component (which is not guaranteed to work outside IE). 完成此操作的方法是通过applet或通过ActiveX插件组件(不能保证在IE之外工作)。

The problem here (that you have already encountered) is that this operation (NetworkInterface) is protected in a regular applet and not allowed by the security manager. 这里的问题(您已经遇到)是此操作(NetworkInterface)在常规小程序中受到保护,并且安全管理器不允许这样做。 To do it, you would have to sign your applet and include a policy-file allowing the applet to access the clients system (ie the NetworkInterface class). 为此,您必须对小程序进行签名,并包括一个允许小程序访问客户端系统的策略文件(即NetworkInterface类)。

NetworkInterface ni = NetworkInterface.getByInetAddress(address);
if (ni != null) 
byte[] mac = ni.getHardwareAddress();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM