wood burning stoves 2.0*
The moose likes Servlets and the fly likes IP address and location of client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "IP address and location of client" Watch "IP address and location of client" New topic
Author

IP address and location of client

Vinay Singh
Ranch Hand

Joined: Dec 15, 2004
Posts: 174
Hi

I want to track the physical location of the client i.e The client who has logged in to my site I want to know their city/town and country.
I think there are 2 steps
1. Get the ip address of the machine
2. Let your app talk to some other add which can give you location of the client based on IP

Does not look like a big task considering google can pin point to the city from which request originated in google analytics.
But in java this look a difficult task.

I cannot get IP from servlet API like getRemoteAddress() because it returns IP of the proxy

In one of the postings in java ranch I found this java script code to get IP address which I think works (I am yet to test it completly)
http://javascript.internet.com/user-details/ip-address.html

Now once I get the API I need to call another service to send me location of this client (If free , nothing like it).

I am not sure how this can be achieved. I also did not find any google API's which could offer this service.

Any suggestions and help would be appreciated.


Technical quiz and interview questions   SCJP 6 mock practice test
Shawn Montague
Greenhorn

Joined: Aug 06, 2008
Posts: 25
They probably don't (at least Google Maps doesn't). You will need to find a service out there that returns the geocode for you - based on IP - so you can find their location.\

I've used these guys for Google Maps geocode lookups and they're good:
http://geocoder.us/

No guarantee, of course
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
If it returns the IP of a proxy, then you may need to check the x-forwarded-for request header. Public proxies will pass the client's IP address in there. If it isn't available either, then you're out of possibilities at the server side. Best what you can do is to run a piece of Java code at the client side which sniffs the local IP address and sends it to the server side. You can do that in form of a signed applet or webstart application which you embed in your JSP.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: IP address and location of client
 
Similar Threads
NetMask,IPAddress clarification
How to get Mac Id of my client machine
Getting IP and location of a client
Getting location information from the IP
can we detect location if GPS is not accesible