[英]How to access client's MAC address in Restful web services
I have a angular application, which is making a rest call as:我有一个 angular 应用程序,它正在将 rest 调用为:
http://localhost:8765/test/iptest
And in my controller:在我的 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?如何使用此请求访问客户端的IP和MAC 地址?
EDIT: I was able to access Client's IP Address using HttpServletRequest as:编辑:我能够使用HttpServletRequest访问客户的 IP 地址:
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但我无法访问MAC 地址
You can't - other than on the local LAN, remote MAC addresses are not exposed to your end point.您不能 - 除了在本地 LAN 上,远程 MAC 地址不会暴露给您的端点。 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.在服务器收到的数据包的以太网 header 中的 MAC 地址将是路径中最后一跳最近的路由器的 MAC 地址。
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.即使在本地 LAN 上,您也无法获取 IP 套接字的此信息 - 查找本地 MAC 地址需要在操作系统的 ARP 表中四处寻找。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.