26

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)

Amir Arad
  • 6,724
  • 9
  • 42
  • 49

5 Answers5

42

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

Community
  • 1
  • 1
atom255
  • 738
  • 5
  • 6
  • 1
    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 08 '09 at 14:47
  • 1
    @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 '17 at 09:55
8

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

cort
  • 1,088
  • 1
  • 11
  • 20
  • 5
    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 '10 at 21:21
1

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.

Steve Claridge
  • 10,650
  • 8
  • 33
  • 35
  • it is so complicated : https://stackoverflow.com/questions/3385/mac-addresses-in-javascript – MrSalesi Apr 22 '19 at 14:03
  • 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 02 '19 at 05:55
0

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

See this thread

AndreiM
  • 4,558
  • 4
  • 36
  • 50
-3

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>