Geo IP client

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 - - [29/Aug/2011:00:00:18 -0700] "GET /blog/geekery/xvfb-firefox.html HTTP/1.1" 200 9767 "" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: 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]


hh said...

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!!

Sunil Patil said...

Try sample project that i have on GitHub I am using JDK 1.7