Two Laptop Bag
The moose likes Servlets and the fly likes Getting IP and location of a client Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Getting IP and location of a client" Watch "Getting IP and location of a client" New topic
Author

Getting IP and location of a client

Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 104
Hi guys,
How can I get the location and IP address from a client's request. Any ideas?


Regards, Fawad Ali.
Software Engineer, Stafona Inc. - My Blog
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2595

Have a look at the docs for getRemoteAddr() method. Note that it yields the IP address of the last proxy - which may probably not be the original client.


Author of ExamLab - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 104
Devaka:
I am replying so late to the thread but my concern here is that how do sites like google or yahoo finds the location of the client. Do they get the IP address and then search through some kind of database table or what? I have to show a client's location (country and City) on a web page but I do not know what will be the best way(approach) to do it.

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2329
Search for "maxmind geoip java".
Ravi Majety
Ranch Hand

Joined: Feb 26, 2009
Posts: 59

check this page

http://stackoverflow.com/questions/2257170/how-to-get-city-name-based-on-ip-address-in-java
Daniel Val
Ranch Hand

Joined: Jan 09, 2012
Posts: 31
Fawad Ali wrote:Devaka:
I am replying so late to the thread but my concern here is that how do sites like google or yahoo finds the location of the client. Do they get the IP address and then search through some kind of database table or what? I have to show a client's location (country and City) on a web page but I do not know what will be the best way(approach) to do it.



Hi,

When google goes to that page, the page will show the location of the google spider (web crawler) , not the location of the other clients. So getRemoteAddr should be fine.

D.
 
 
subject: Getting IP and location of a client
 
Threads others viewed
[B&S] - Need help determining a plan of action with options window
get location of client?
can we detect location if GPS is not accesible
javax.naming.CommunicationException: Destination unreachable
How to find country name and language in java
IntelliJ Java IDE