Im currently deploying my app using apache tomcat 7. I want to get the Ip addressess of users who visit my local site so that i could keep tract the number of visits per IP address. Could someone help me? I bet HttpServletRequest.getRemoteAddr() only returns the 127.0.0.1. Im using JSP/Servlet for this.
Asked
Active
Viewed 582 times
0
-
Look at [here](http://stackoverflow.com/questions/4678797/how-do-i-get-the-remote-address-of-a-client-in-servlet) – Sas Nov 28 '14 at 20:53
2 Answers
0
Try this:
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if (ipAddress == null) {
ipAddress = request.getRemoteAddr();
}

FakirTrappedInCode
- 649
- 9
- 29
-
-
Seems like your apache web server is redirecting to this 127.0.0.1 based on Rewrite rules – FakirTrappedInCode Nov 28 '14 at 12:52
-
@AdrianMesa you are accessing you web url from your local system that's why you are getting this ip `127.0.0.1` – Altmish-E-Azam Nov 29 '14 at 06:15
0
To get remote IP/LOCAL IP address you need to know about HTTP Headers where you can get all poosible headers which you required use below code to get headers name and their values.
java.util.Enumeration em = request.getHeaderNames();
while(em.hasMoreElements()){
String key = (String)em.nextElement();
key = key.trim();
System.out.println("Header Name :: "+key+"||Header Value ::"+reqeust.getHeader(key));
}
Implement above code in your project and access your website from another system or server and trace all above headers values. Hope you will find what do you want!

Altmish-E-Azam
- 1,561
- 1
- 13
- 24