示例#1
0
     echo '</form>';
     echo '<form method="get" action="/t/ipcheck/user">';
     echo 'Search by username: '******'user', $session->username) . '<br/><br/>';
     echo xhtmlSubmit('Search');
     echo '</form>';
     break;
 case 'ip':
     // query ip info
     $ip = '';
     if (!empty($_GET['ip'])) {
         $ip = $_GET['ip'];
     }
     if (!$ip) {
         die('meh');
     }
     $geoip = IPv4_to_GeoIP($ip);
     echo '<h1>' . $ip . ' (' . gethostbyaddr($ip) . ')</h1>';
     echo '<br/><br/>';
     $list = LoginEntry::getUsersByIP($ip);
     echo 'This IP is associated with ' . count($list) . ' registered users:<br/>';
     foreach ($list as $user_ip) {
         echo UserLink::render($user_ip) . '<br/>';
     }
     echo '<hr/>';
     echo '<a href="http://www.dnsstuff.com/tools/whois.ch?ip=' . $ip . '" target="_blank">Perform whois lookup</a><br/>';
     echo '<a href="http://www.dnsstuff.com/tools/tracert.ch?ip=' . $ip . '" target="_blank">Perform traceroute</a><br/>';
     echo '<a href="http://www.dnsstuff.com/tools/ping.ch?ip=' . $ip . '" target="_blank">Ping IP</a><br/>';
     echo '<a href="http://www.dnsstuff.com/tools/city.ch?ip=' . $ip . '" target="_blank">Lookup city from IP</a><br/>';
     echo '<hr/>';
     //Admin notes
     echo CommentViewer::render(IP, $geoip);
示例#2
0
/**
 * Checks a IPv4 address against a whitelist
 *
 * @param $ip IPv4 address in GeoIP or human readable format
 * @param $matches array of IPv4 addresses
 * @return true if $ip address is found in the $matches list
 */
function match_ip($ip, $matches)
{
    if (!is_numeric($ip)) {
        $ip = IPv4_to_GeoIP($ip);
    }
    foreach ($matches as $chk) {
        $a = explode('/', $chk);
        //check against "80.0.0.0/8" format
        if (count($a) == 2) {
            $lo = IPv4_to_GeoIP($a[0]);
            if ($ip >= $lo) {
                $hi = $lo + bindec('1' . str_repeat('0', 32 - $a[1])) - 1;
                //echo "lo: ".GeoIP_to_IPv4($lo)."   (".$lo.")\n";
                //echo "hi: ".GeoIP_to_IPv4($hi)."   (".$hi.")\n";
                if ($ip <= $hi) {
                    return true;
                }
            }
        } else {
            if ($ip == IPv4_to_GeoIP($chk)) {
                return true;
            }
        }
    }
    return false;
}
示例#3
0
 public function test1()
 {
     $this->assertEquals(IPv4_to_GeoIP('192.168.0.1'), 3232235521);
     $this->assertEquals(GeoIP_to_IPv4(IPv4_to_GeoIP('192.168.0.1')), '192.168.0.1');
 }