cancel
Showing results for 
Search instead for 
Did you mean: 

Getting IP Addresses

i045323
Employee
Employee
0 Kudos

Hi,

I have a simple HTML5 application running on HCP. I need to find out the IP address of the client running this application.

any idea how to do this ?

thnx,

Pramod

Accepted Solutions (1)

Accepted Solutions (1)

former_member191806
Active Participant
0 Kudos

Hello Pramod,

As far as I know, this can not be done using just purely javascript / HTML5. I have two ideas on how you could accomplish this through other ways:

  • You can create a Java app, which can contain your HTML5 app. This Java application would contain a servlet which can determine the client IP (see HttpServletRequest (Java EE 6 ), you would use the method getRemoteAddr() and/or the method getHeader("X-FORWARDED-FOR")).
  • You can rely on a 3rd party REST service, on which you would perform an AJAX request from javascript. This is not as desirable as the other idea, because you would depend on 3rd party services. Check out hostip.info for an example of such 3rd party site.

Regards,

Serban

NikiD
Employee
Employee
0 Kudos

X-Forwarded-For header presence depends on the underlaying infrastructure. Hence it MAY be added by a proxy or a load balancer as the header itself is not standardized.

former_member191806
Active Participant
0 Kudos

That is true, although not standardized, it is used by most / all proxy servers (a simple google search will reveal that it is a "de facto" standard). This header check would be needed because the getRemoteAddr() method will return null if the user is behind a proxy. Unfortunately, IPs can be masked by the infrastructure, so there is no 100% proof way that gets the real IP. You have to work with what you have

NikiD
Employee
Employee
0 Kudos

If you use Java Servlet based web container the implementation of getRemoteAddr will try to figure out the last communication peer ip address. In HCP we use Apache Tomcat as a web container hence getRemoteAddr is implemented in a way it will not return null. Example : NIO non blocking connector (o.a.coyote.http11.Http11NioProcessor) Of course that differs from the client origin in case of proxy or reverse proxy instances being part of the communication path.

Answers (0)