0

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.

  • 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 Answers2

0

Try this:

String ipAddress = request.getHeader("X-FORWARDED-FOR");
   if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
   }
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