Resolve IP to Country Name in Java

Getting country name from IP address can be done offline with help of a simple Java library.

Download IP2C file from Here- http://files.firestats.cc/ip2c/ip2c-2.0.0.zip


IP2C resolves country names from ip using a binary File. It uses database provided by Webhosting.info and also supports Software77  Database.

It converts the CSV database into binary file and supports the search straight on the file ,in memory or in a memory mapped file.

Here are Steps to use this library with Java.

  • Extract the downloaded file
  • Add ip2c.jar to the Build Path 
  • Copy ip-to-country.bin file into your project folder
Usage (In Memory):
import java.io.IOException;
import net.firefang.ip2c.Country;
import net.firefang.ip2c.IP2Country;

public class ip {

	public static void main(String args[]) throws IOException{

	String iptest = "";
	int caching1 = IP2Country.MEMORY_CACHE;
	IP2Country ip2c = new IP2Country(caching1);
	Country c = ip2c.getCountry(iptest);
	if (c == null)	{


For Usage with PHP and other details see IP2C