Example #1
0
 function test_getCountryNameByHostName()
 {
     foreach ($this->hosts as $host => $expected) {
         $rv = fbGeoIP_Free_Ascii::getCountryNameByHostName($host);
         $this->assertTrue($rv, "host='{$host}'");
         //			$this->assertEquals($expected, $rv, "host='$host'");
     }
 }
 function test_fbBinarySearch_File_1()
 {
     $ips = array('0.0.0.0' => "000.000.000.000\t000.255.255.255\tUS", '10.0.0.1' => "010.000.000.000\t010.255.255.255\tI0", '10.255.255.255' => "010.000.000.000\t010.255.255.255\tI0", '127.0.0.1' => "127.000.000.000\t127.255.255.255\tL0", '127.0.0.2' => "127.000.000.000\t127.255.255.255\tL0", '127.255.255.255' => "127.000.000.000\t127.255.255.255\tL0", '172.16.0.0' => "172.016.000.000\t172.031.255.255\tI0", '172.31.255.255' => "172.016.000.000\t172.031.255.255\tI0", '192.168.0.0' => "192.168.000.000\t192.168.255.255\tI0", '192.168.0.1' => "192.168.000.000\t192.168.255.255\tI0", '192.168.255.255' => "192.168.000.000\t192.168.255.255\tI0", '255.0.0.0' => "221.097.211.000\t255.255.255.254\tUS", '255.255.255.254' => "221.097.211.000\t255.255.255.254\tUS", '255.255.255.255' => "255.255.255.255\t255.255.255.255\t--");
     foreach ($ips as $ip => $expected) {
         $ipf = fbGeoIP_Free_Ascii::_formatIP4address($ip);
         $bsf =& new fbBinarySearch_File($this->_file);
         $rv = $bsf->search($ipf);
         $rv = trim($rv);
         $this->assertEquals($expected, $rv, "ip='{$ip}' ipf='{$ipf}' gettype(expected)=" . gettype($expected) . ' gettype(rv)=' . gettype($rv));
     }
 }
Example #3
0
<?php

// $CVSHeader: _freebeer/www/demo/GeoIP.Free.Ascii.php,v 1.3 2004/03/07 17:51:33 ross Exp $
// Copyright (c) 2002-2004, Ross Smith.  All rights reserved.
// Licensed under the BSD or LGPL License. See license.txt for details.
require_once './_demo.php';
require_once FREEBEER_BASE . '/lib/GeoIP/Free/Ascii.php';
echo html_header_demo('fbGeoIP_Free_Ascii Class');
echo "<pre>\n";
$ips = array('0.0.0.0', '10.0.0.1', '10.255.255.255', '127.0.0.1', '127.0.0.2', '127.255.255.255', '127.255.255.255', '172.16.0.0', '172.31.255.255', '192.168.0.0', '192.168.0.1', '192.168.255.255', '217.194.16.0', '217.194.16.1', '255.0.0.0', '255.255.255.254', '255.255.255.255', '9.20.0.0');
foreach ($ips as $ip) {
    $rv = fbGeoIP_Free_Ascii::getCountryIDByIP($ip);
    printf("%-20s: '%s'\n", $ip, $rv);
}
echo "\n";
flush();
$hosts = array('localhost', 'sf.net');
foreach ($hosts as $host) {
    $rv = fbGeoIP_Free_Ascii::getCountryIDByHostName($host);
    printf("%-20s: '%s'\n", $host, $rv);
}
?>
<address>
$CVSHeader: _freebeer/www/demo/GeoIP.Free.Ascii.php,v 1.3 2004/03/07 17:51:33 ross Exp $
</address>

</body>
</html>
Example #4
0
 function getCountryNameByHostName($name)
 {
     include_once FREEBEER_BASE . '/lib/ISO3166.php';
     $cc = fbGeoIP_Free_Ascii::getCountryIdByHostName($name);
     $rv = fbISO3166::getCountryName($cc);
     return $rv ? $rv : $cc;
 }