Version 15 (modified by omry, 16 years ago) (diff)



IP2C is a small library that provides IP to country resolution using a binary file.
The binary file is compiled from ip-to-country free database and takes only 460kb (the CSV takes about 3.5mb).


  • Command line
  • Java
  • PHP


IP2C works directly on a binary file, and does not load it into memory, so required memory is minimal.
PHP: My tests shows that PHP code resolves an IP in 4ms. this means you can do about 250 searches in a second.
Java: My tests show that Java code resolves an IP address in 0.0018 ms, this means you can do more than 7140 searches in a second. (This is too good to be true, and is probably the result of disk cache does by the OS)


ip2c 1.1


Browse source

Command line (requires java in path)

Usage : To resolve an IP address: java -jar ip2c.jar ip-address Output format: if not found: UNKNOWN

if found: 2C 3C NAME

Example: java -jar ip2c.jar Outputs: IL ISR ISRAEL

To build binary file from CSV: java -jar ip2c csv_file bin_file

Java code

String ip =;
IP2Country ip2c = new IP2Country();
Country c = ip2c.getCountry(ip);
if (c == null)
        // will output IL ISR ISRAEL
        System.out.println(c.get2cStr() + " " + c.get3cStr() + " " + c.getName());      


Install the ip2c.php and the binary file in the same directroy.


$ip2c = new ip2country();
$res = $ip2c->get_country("");
if ($res == false)
  echo "not found";
  $o2c = $res['id2'];
  $o3c = $res['id3'];
  $oname = $res['name'];
  echo "$o2c $o3c $oname"; // will output IL ISR ISRAEL