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
–
–
–
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>
$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.