Sometimes you might want to find out location of where your web traffic is coming from. In that case you might want to look into the access log generated by your web server, it will give you ip address of the client. ONce you have the client's ip you can use GeoIP database to look up city, state, country for that ip. You can download the sample project from
here
This is how a sample log line looks like
125.215.163.73 - - [29/Aug/2011:00:00:18 -0700] "GET /blog/geekery/xvfb-firefox.html HTTP/1.1" 200 9767 "http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBkQFjAA&url=http%3A%2F%2Fwww.semicomplete.com%2Fblog%2Fgeekery%2Fxvfb-firefox.html&rct=j&q=xvfb%20firefox%20fully%20loaded%20screenshot&ei=zDhbTvX6N-jmiAK5_7i4CQ&usg=AFQjCNEFaYxjYoKmLd5CLaG3SbQNStGkLg&sig2=oZnDDXKzFB8uwbDg5aNi2w&cad=rja" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.20) Gecko/20110803 Firefox/3.6.20 FirePHP/0.5"
Now you can download GeoIP database from
MaxMind, then create a simple Java Client that given a ip address will print its geo location like this, you can download source code for my project from
here
Your output should look something like this
City Tokyo
ZIP Code null
Country Japan
Location Location [latitude=35.685, longitude=139.7514, timeZone=Asia/Tokyo]
City Fremont
ZIP Code 94536
Country United States
Location Location [latitude=37.567, longitude=-121.9829, metroCode=807, timeZone=America/Los_Angeles]
3 comments:
i have installed the geoip2 jar in my eclipse and write a simple project just like you,but when create DatabaseReader instance it always said there something wrong ,can you help me fix it?or what's your version of you java jdk ? thanks!!
Try sample project that i have on GitHub https://github.com/sdpatil/GeoIPClient. I am using JDK 1.7
Thanks for info....
Website development in Bangalore
Post a Comment