1

I have a angular application, which is making a rest call as:

http://localhost:8765/test/iptest

And in my controller :

@GetMapping(value = "test/iptest")
public ResponseEntity<Object> doTest() {
    log.debug("Inside Test");
    return new ResponseEntity<>("Test success", HttpStatus.OK);
}

How do I access client's IP and MAC address using this request?

EDIT: I was able to access Client's IP Address using HttpServletRequest as:

    import javax.servlet.http.HttpServletRequest;
    import javax.ws.rs.core.Context;

    @GetMapping(value = "test/iptest")
    public ResponseEntity<Object> doTest(@Context HttpServletRequest request) {
        log.debug("IP Address is:"+request.getRemoteAddr());
        return new ResponseEntity<>("Test success", HttpStatus.OK);
    }

But I'm not able to access MAC ADDRESS

SeleM
  • 9,310
  • 5
  • 32
  • 51
Harihara_K
  • 174
  • 16

1 Answers1

3

You can't - other than on the local LAN, remote MAC addresses are not exposed to your end point. The MAC address in the Ethernet header of the packet received at the server will be that of the nearest router that was the last hop in the path.

Even on the local LAN you cannot get this information for an IP socket - looking up a local MAC address requires poking around in the OS's ARP tables.

Alnitak
  • 334,560
  • 70
  • 407
  • 495