I have a web application using Java, JSP. I want to make sure a user can only answer the same question on his/her same device ONCE. I try to check IP address on the user's computer. Once the device IP address is used, user can't answer the same question again on the device.
I try to capture the IP address as
String ip = request.getRemoteAddr();
System.out.println("IP Address: "+ip);
but the ip printed out as the following.
IP Address: 0:0:0:0:0:0:0:1
Please let me how to capture user's device IP address correctly? Or any better way to make sure the same device can't be used twice or more for the same question.
Thanks in advance
UPDATE I added the following code to jsp page trying to capture customer's IP address, but I still keep getting production server IP addresses (I uploaded the app to production site). Could you please let me know why? I should get customers device IP address.
Thanks in advance!
String ip = "";
ip = request.getHeader("X-Forwarded-For");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
System.out.println("ip: " +ip);