Home > Net >  Retrieving MAC of remote client from JAVA socket
Retrieving MAC of remote client from JAVA socket

Time:11-09

Below is a Java snippet for my server that accepts a TCP connection.

InetAddress inetAddress = InetAddress.getByName("192.168.2.13");
ServerSocket serverSocket = new ServerSocket(5020, 100, inetAddress);
   
//accept connection
Socket mSocket = serverSocket.accept();

Is there any way to go to the lower layer to retrieve the MAC address of the remote client (I do not want the MAC address of local server) that initiated the request to my server? I would like to write a code that looks up the remotes client's MAC and IP address in a table before the server accepts the connection but I am experiencing difficulties doing so. Thanks!

CodePudding user response:

No, you can't get the MAC address of the remote user using the link layer. Suppose that the remote user is A and your server is B. Between this points (A and B) there C, D and E routers.

The remote user MAC address will only be sent in the frame that encapsulate the IP datagram with destination MAC address of one of the interfaces of C and then router C will use one of its interfaces MAC address to sent it to D with the destination MAC address as one of the interfaces of D, and ...etc (until the final destination is the MAC address of your server).

So when the IP address of the remote user will not change (assuming he doesn't use a VPN), the source MAC address will change.


If you want to get the MAC address of the remote user, you have to include it in the messages the client sent to your server. Unless you're the developer of the client I don't think there's another way around this.

  • Related