= IP2C = IP2C is a small library that provides IP to country resolution using a binary file.[[BR]] IP2C is shipped with a database from Webhosting.info, but supports the following : * Webhosting.info : [http://ip-to-country.webhosting.info/ download database] * Software77 : [http://software77.net/cgi-bin/ip-country/geo-ip.pl download database] The CSV file from those sources is converted into a highly efficient binary format:[[BR]] * Webhosting.info database is converted from a ~5MB CSV to a ~550k binary. * Software77 database is converted from a ~5mb CSV to ~250k binary. == License == IP2C is released under the terms [http://www.gnu.org/licenses/gpl.html GPL v2]. == Supports == * Command line * Java * PHP == Performance == All tests done on an Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GH[[BR]] '''PHP:''' * '''No cache:''' 5000 searches/sec (Fast startup, slow query) * '''Memory cache:''' : 5700 searches/sec (Slow startup, fastest query) '''Java:''' * '''No cache:''' 13900 searches/second. (Fast startup, slow query) * '''Memory mapped file:''' 265k searches/second. (Fast startup, fast query) * '''Memory cache:''' 281k searches/second. (Slow startup, fastest query) == Download == [http://admin.firestats.cc/ccount/click.php?id=74 IP2C 2.0.0] (Database version : '''2009.02.26''')[[BR]] See the [wiki:ip2c-changelog changelog]. == Source == [source:/trunk/ip2c Browse source] == Command line (requires java in path) == Usage : To resolve an IP address: {{{ java -jar ip2c.jar -r ip-address }}} Output format: if not found: '''UNKNOWN''' if found: '''2C 3C NAME''' Example: {{{ java -jar ip2c.jar -r 85.64.225.159 }}} Outputs: '''IL ISR ISRAEL''' To build binary file from CSV: {{{ java -jar ip2c.jar -c csv_file [bin_file] }}} bin_file is optional, if not specified, file.csv will be converted to file.bin. == Java code == {{{ #!java String ip = 85.64.225.159; int caching1 = IP2Country.NO_CACHE; // Straight on file, Fastest startup, slowest queries int caching2 = IP2Country.MEMORY_MAPPED; // Memory mapped file, fast startup, fast quries. int caching3 = IP2Country.MEMORY_CACHE; // load file into memory, slowerst startup, fastest queries IP2Country ip2c = new IP2Country(caching1); Country c = ip2c.getCountry(ip); if (c == null) { System.out.println("UNKNOWN"); } else { // will output IL ISR ISRAEL System.out.println(c.get2cStr() + " " + c.get3cStr() + " " + c.getName()); } }}} == PHP == Install the ip2c.php and the binary file in the same directroy. {{{ #!php get_country("85.64.225.159"); if ($res == false) echo "not found"; else { $o2c = $res['id2']; $o3c = $res['id3']; $oname = $res['name']; echo "$o2c $o3c $oname"; // will output IL ISR ISRAEL } ?> }}}