简体   繁体   中英

how to get a client's MAC address from HttpServlet?

I was asked to write a servlet that collects client's details such as ip, mac address etc.

getting his IP is pretty straight-forward ( request.getRemoteAddr() ) but I dont find an elegant way to get his MAC address.

seems reasonable that the web server has access to data such as Mac address etc, since it gets the TCP packets and all. does this data registers somewhere? is it accessible?

(I'm working on top of Tomcat6)

You're probably not going to get what you want. (the client's MAC address)

If the server is close enough (directly connected via hub or maybe a switch) you can ARP for the MAC Address. If you do this for an IP across the Internet you're probably going to get the inside interface of the closest Router or Switch.

Because of the way TCP/IP works the MAC address used in the 'frame' will get ripped off and re-assembled each at each hop the information takes between the server and the host.

替代文字

Encapsulation

TCP / IP ...你无法获得MAC地址,这是一个太低的AFAIK层

I believe that clients need to allow for this to happen in their JVM:

See this thread

This isn't possible through the HttpServlet class.

The only way I can think of possibly gettnig a users MAC address is to use Javascript on the client side to retrieve it and then place it in a cookie that your server can then read. But, I don't know if it's possible to get MAC addr using Javascript - would seem like a security risk for a browser to allow you to do this as it's going outside the browser's sandbox but maybe there's some hack around to do it.

this script works the best 100% probability that it works on you localhost but you have to check this with your webhost

there is a php code that is much more better

<font color="black" face="courier new">
<b>mac/linux/android</b>(arp -an)<br>

<?php
$mac = system('arp -an');
echo $mac;
echo "<hr>";
?>
<b>mac/linux/android</b>(ifconfig)<br>
<?php
$macall = system('ifconfig');
echo $macall;
echo "<hr>";
?>
<b>pc/win</b>(ipconfig /all)<br>
<?php
$pc = system('ipconfig /all');
echo $pc;
echo "<hr>";
?>
</font>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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