Version 10 (modified by omry, 14 years ago) (diff) |
---|
IP2C
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).
Supported languages:
- Java
- PHP (Soon)
Performance
Current Java code takes less then 20ms to lookup an ip address on my computer.
this is working directly on the file, so memory usage is minimal (it does not load the whole file into memory).
License
IP2C is licensed under GPL2, if you would like to use it in a non-gpl application please Contact me to obtain a non-gpl license.
JAVA
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 85.64.225.159 Outputs: IL ISR ISRAEL
To build binary file from CSV: java -jar ip2c csv_file bin_file
PHP
Install the ip2country.php and the binary file in the same directroy.
<?php require_once('ip2country.php'); $ip2c = new ip2country(); $res = $ip2c->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 } ?>