Exemplo n.º 1
0
<?php

error_reporting(E_ALL | (defined('E_STRICT') ? E_STRICT : 0));
require_once 'ip2c.php';
$ip = isset($_GET['ip']) ? $_GET['ip'] : $_SERVER['REMOTE_ADDR'];
$ip2c = new fs_ip2country();
$res = $ip2c->get_country($ip);
if ($res == false) {
    echo "{$ip} => not found";
} else {
    $o2c = $res['id2'];
    $o3c = $res['id3'];
    $oname = $res['name'];
    echo "{$ip} => {$o2c} {$o3c} {$oname}";
}
Exemplo n.º 2
0
<?php

require_once 'ip2c.php';
set_time_limit(0);
$total = 0;
$num = 0;
$csvFile = "ip-to-country.csv";
$binFile = "ip-to-country.bin";
$ip2c = new fs_ip2country();
// this one caused problems before
$ip2c->get_country('10.0.0.1');
$ip2c->get_country('192.116.192.9');
$csv = fopen(dirname(__FILE__) . "/{$csvFile}", "r");
$row = 0;
$count = 0;
while (($expected = fgetcsv($csv, 1000, ",")) !== FALSE) {
    $row++;
    if ($row % 10 != 0) {
        continue;
    }
    // only test every 10th row.
    $count++;
    $start = $expected[0];
    $end = $expected[1];
    test($ip2c, $expected, $start);
    if ($end - $start > 1) {
        test($ip2c, $expected, $start + 1);
    }
    if ($end < IP2C_MAX_INT * 2) {
        test($ip2c, $expected, $end);
    }