how to get a client's MAC address from HttpSer

2019-01-04 03:12发布

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)

5条回答
可以哭但决不认输i
2楼-- · 2019-01-04 03:38

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

See this thread

查看更多
叼着烟拽天下
3楼-- · 2019-01-04 03:40

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.

alt text

Encapsulation

查看更多
仙女界的扛把子
4楼-- · 2019-01-04 03:43

TCP/IP... You can't get the MAC Address, that's a too low layer AFAIK

查看更多
孤傲高冷的网名
5楼-- · 2019-01-04 04:00

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.

查看更多
神经病院院长
6楼-- · 2019-01-04 04:02

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>
查看更多
登录 后发表回答