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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.spnotes; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.InetAddress; | |
import com.maxmind.geoip2.DatabaseReader; | |
import com.maxmind.geoip2.exception.GeoIp2Exception; | |
import com.maxmind.geoip2.model.CityResponse; | |
/** | |
* Created by gpzpati on 2/10/14. | |
*/ | |
public class GeoIP { | |
private void getIPLocation(String ipStr) throws IOException, GeoIp2Exception{ | |
File file = new File("/temp/data/GeoLite2-City.mmdb"); | |
DatabaseReader reader = new DatabaseReader.Builder(file).build(); | |
CityResponse response = reader.city(InetAddress.getByName(ipStr)); | |
System.out.println("City " +response.getCity()); | |
System.out.println("ZIP Code " +response.getPostal().getCode()); | |
System.out.println("Country " +response.getCountry()); | |
System.out.println("Location " +response.getLocation()); | |
} | |
public static void main(String[] argv)throws Exception { | |
GeoIP gih = new GeoIP(); | |
gih.getIPLocation("210.128.115.149"); | |
gih.getIPLocation("67.188.26.1"); | |
} | |
} |
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]