I need to distinguish between client requests coming from devices connected to a wired LAN and those using a hotspot in my Spring Boot application. Here’s the situation: System A is the server, and System B is another device connected to the same wired LAN network as System A. Recently, System B started sharing its internet as a hotspot, and a new device, System C, connected to this hotspot. Now, System C is trying to access an application hosted on port 8080 of System A. However, when System A logs the IP address of the client, it shows System B’s IP address instead of System C’s, which is connected through System B’s hotspot. How can I ensure that System C’s IP address is correctly identified and prevent it from accessing a specific URL (/loginurl
) in my Spring Boot application? Currently, I’m using httpServletRequest.getRemoteAddr()
to get the client’s IP address, but it returns System B’s IP address instead of System C’s. I want to restrict access to hotspot devices and allow access only to wired LANs.
I tried the below code to find whether the request is from Hotspot or Wired LAN but all are showing null.
System.out.println("------------" + request.getHeader("X-Forwarded-For")); System.out.println("------------" + request.getHeader("X-Real-Ip")); System.out.println("------------" + request.getHeader("Forwarded"));
I got this requirement using JavaScript but the attacker may intercept and change the request. So I want to do this validation on the Server side.