I am trying to develop a Java web application (Servlet) that I need to get clients IP address.
Please do not consider this a duplicate question, because I have tried all possible answers that are available in stackoverflow.
Below is my code:
one)
String ipAddress = request.getRemoteAddr();
In this case, most of the volume I get is the "Default Gateway Address" (147.120.1.5). not my device IP address (174.120.100.17).
2)
String ipAddress = request.getHeader("X-FORWARDED-FOR"); if (ipAddress == null) { ipAddress = request.getRemoteAddr(); }
In this case, most of the volume I get is the "Default Gateway Address" (147.120.1.5). not my device IP address (174.120.100.17).
3)
InetAddress IP=InetAddress.getLocalHost(); System.out.println(IP.getHostAddress());
In this case, I got the IP address of the server (147.120.20.1).
My IP address is at 147.120.100.17. No, I donβt know how to get the real IP address of the client. Please make an answer.
Many thanks.
java servlets ip
Samith dilshan
source share