相关文章推荐
爱旅游的感冒药  ·  验证视图状态 MAC ...·  1 周前    · 
沉稳的生姜  ·  c# - WPF How to ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

In re-reading other answers I agree that if you get people's computers to give up their internal config you can do better, but I doubt any security model would allow it. Same thing as trying to get someone's internal IP address, the best you can usually do is get the router that's doing address translation. atom255 May 8, 2009 at 14:47 @atom225 I'm not an expert, but by seeing the image you posted, I can imagine a scenario where we ask & send the MAC address in the application layer, what do you think about my idea? ziMtyth Oct 31, 2017 at 9:55 the MAC is available, however, irrelevant since it is most likely not the client's NIC but some the MAC of the closest device to the server. Tzury Bar Yochay Jan 10, 2010 at 21:21

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.

You are right. If client will provide, they will be exposing their details & security breach is easy. One need to do proper R&D before doing this Satish Patro Nov 2, 2019 at 5:55

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.