[英]how to find client system mac address in web application
I need to find client MAC address who is accessing my website. 我需要找到正在访问我的网站的客户端MAC地址。 I have tried with java code.
我尝试使用Java代码。
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while(networkInterfaces.hasMoreElements())
{
NetworkInterface network = networkInterfaces.nextElement();
System.out.println("network : " + network);
byte[] mac = network.getHardwareAddress();
if(mac == null)
{
System.out.println("null mac");
}
else
{
System.out.print("MAC address : ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++)
{
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
val = sb.toString();
System.out.println(sb.toString());
break;
}
}
} catch (SocketException e){
e.printStackTrace();
}
But it display as "network : name:eth0 (eth0) MAC address : EC-A8-6B-77-A9-AD" for all client system. 但是对于所有客户端系统,它都显示为“网络:名称:eth0(eth0)MAC地址:EC-A8-6B-77-A9-AD” 。
how can i do this? 我怎样才能做到这一点?
Server side Java code will never return the client's MAC address. 服务器端Java代码将永远不会返回客户端的MAC地址。
For that you would need a code running at the client. 为此,您需要在客户端运行的代码。 For example in IE you could get that with Javascript+ActiveX.
例如,在IE中,您可以使用Javascript + ActiveX来实现。 In other browsers (including IE) you could do that with a Java Applet, but security restraints might prevent the applet to access system information including the MAC address.
在其他浏览器(包括IE)中,您可以使用Java Applet来执行此操作,但是安全限制可能会阻止Applet访问包括MAC地址在内的系统信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.