I know this question is raised too many times ago but my problem is different. I want to detect the ip address of client which can be anywhere in the world. I googled and found some way but it is not working.
When I ask our network administrator, he told me that our proxy server has ip 192.xxx.xxx.xxx and for the outside of our company network the ip is 180.xxx.xxx.xxx which is bind to our proxy server's ip address[192.xxx.xxx.xxx]
Here is the code that I tried. This code resides in servlet. All are returning null. Thanks in advance...
String ipAddress;
ipAddress = request.getHeader("X-FORWARDED-FOR");
System.out.println(ipAddress);
if (ipAddress == null) {
ipAddress = request.getRemoteAddr();
System.out.println(ipAddress);
}
ipAddress = request.getHeader("HTTP_X_FORWARDED_FOR");
System.out.println(ipAddress);
ipAddress = request.getHeader("X-Forwarded-For");
System.out.println(ipAddress);
ipAddress = request.getHeader("Proxy-Client-IP");
System.out.println(ipAddress);
ipAddress = request.getHeader("WL-Proxy-Client-IP");
System.out.println(ipAddress);
ipAddress = request.getHeader("HTTP_CLIENT_IP");
System.out.println(ipAddress);
ipAddress = request.getHeader("HTTP_X_FORWARDED_FOR");
System.out.println(ipAddress);