Skip to content

Instantly share code, notes, and snippets.

@bfg bfg/gist:6377619
Created Aug 29, 2013

Embed
What would you like to do?
import java.util.*;
import com.maxmind.geoip.*;
public class L {
public static void main (String[] args) throws Exception {
// initialize lookup services...
ArrayList<LookupService> svcs = new ArrayList<LookupService>();
svcs.add(new LookupService("/usr/share/GeoIP/GeoIPv6.dat"));
svcs.add(new LookupService("/usr/share/GeoIP/GeoIP.dat"));
int i = 0;
for (LookupService ls: svcs) {
boolean isv6 = (args[0].indexOf(":") >= 0);
Country c = (isv6) ? ls.getCountryV6(args[0]) : ls.getCountry(args[0]);
System.out.println("Country for " + args[0] + ": " + c.getCode());
}
}
}
/*
Produces:
$ java -cp ~/git/geoip-api-java/target/geoip-api-1.2.11-SNAPSHOT.jar:. L ::ffff:193.2.1.66
Country for ::ffff:193.2.1.66: SI
Country for ::ffff:193.2.1.66: --
$ java -cp ~/git/geoip-api-java/target/geoip-api-1.2.11-SNAPSHOT.jar:. L 193.2.1.66
Country for 193.2.1.66: --
Country for 193.2.1.66: SI
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.