GeoIP PHP Script
GeoIP PHP Script
I made this script utility to check what country is some ip, you need GeoIP Database
I hope you have PHP in your path:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #!/usr/bin/php -q <? if (count($_SERVER['argv']) <= 1) { echo "use: geoip xxx.xxx.xxx.xxx\n"; } else { $ip=$_SERVER['argv'][1]; $out=sprintf("%u", ip2long($ip)); // don't ask why, you need this line $sql="SELECT country_name FROM geoip WHERE ($out BETWEEN ip_begin AND ip_end)"; $link = mysql_connect('localhost','root',''); // HOST, USER, PASS mysql_select_db('GEOIP'); // DATABASE $query = mysql_query($sql,$link); while ($row = @mysql_fetch_array($query,MYSQL_ASSOC)) { $data[] = $row; } if (count($data) == 1) { echo $data[0]['country_name']."\n"; } else { echo "Unknown\n"; } } ?> |
Examples:
~$ geoip 79.130.90.12 Greece ~$ geoip 207.33.11.33 United States ~$ geoip 148.234.13.23 Mexico
I think i made a good tool.