Esempio n. 1
0
function inet_pton($ip)
{
    # ipv4
    # check for a IPv4-mapped address
    if (preg_match('#^::ffff:([0-9A-F]{1,4}):([0-9A-F]{1,4})$#i', $ip, $match)) {
        $match[1] = str_pad($match[1], 4, '0', STR_PAD_LEFT);
        $match[2] = str_pad($match[2], 4, '0', STR_PAD_LEFT);
        $ip1 = hexdec(substr($match[1], 0, 2));
        $ip2 = hexdec(substr($match[1], 2));
        $ip3 = hexdec(substr($match[2], 0, 2));
        $ip4 = hexdec(substr($match[2], 2));
        $ip = pack('N', NET::ip2long("{$ip1}.{$ip2}.{$ip3}.{$ip4}"));
    } else {
        if (strpos($ip, '.') !== FALSE) {
            # check for a hybrid IPv4-compatible address
            $pos = strrpos($ip, ':');
            if ($pos !== FALSE) {
                $ip = substr($ip, $pos + 1);
            }
            # finally make the binary code
            $ip = pack('N', NET::ip2long($ip));
        } else {
            if (strpos($ip, ':') !== FALSE) {
                # fix shortened ip's
                $c = substr_count($ip, ':');
                if ($c < 7) {
                    $ip = str_replace('::', str_pad('::', 9 - $c, ':'), $ip);
                }
                # now fix the group lengths
                $ip = explode(':', $ip);
                $res = '';
                foreach ($ip as $seg) {
                    $res .= str_pad($seg, 4, '0', STR_PAD_LEFT);
                }
                # finally make the binary code
                $ip = pack('H' . strlen($res), $res);
            }
        }
    }
    return $ip;
}
Esempio n. 2
0
 public static function broadcast($ip, $cidr)
 {
     if ($cidr > 32) {
         return false;
     }
     if ($ip = FILTER::ipv4($ip, true)) {
         return long2ip(NET::ip2long($ip, true) - (0xffffffff << 32 - $cidr) - 1);
     }
     return false;
 }
Esempio n. 3
0
             $cpgtpl->assign_block_vars('seclist', array('L_NAME' => $ip, 'L_BAN_LEVEL' => get_ban_type($row['ban_time'] - $MAIN_CFG['_security']['bantime']), 'S_BACKGROUND' => ++$counter % 2 ? ' class="distinct"' : '', 'U_DETAILS' => URL::admin('&amp;ip=' . $url)));
         }
     }
     $cpgtpl->assign_vars(array('L_BAN_NAME' => 'IP', 'L_BAN_TYPE' => 'Banned on', 'U_PAGE' => 'floods'));
     $cpgtpl->set_handle('options', 'admin/security/options.html');
     $cpgtpl->display('options');
 } else {
     if (isset($_GET['ips'])) {
         if (Security::check_post()) {
             if (!empty($_POST['mark'])) {
                 foreach ($_POST['mark'] as $ip) {
                     $ban_ipv4_s = $ban_ipv4_e = '';
                     if (preg_match('#^([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})( - )?([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})?$#', $ip, $match)) {
                         $ban_ipv4_s = NET::ip2long($match[1]);
                         if (!empty($match[2])) {
                             $ban_ipv4_e = 'AND ban_ipv4_e=\'' . NET::ip2long($match[3]) . '\'';
                         }
                         if (!empty($ban_ipv4_s)) {
                             $db->sql_query('DELETE FROM ' . $prefix . "_security WHERE ban_ipv4_s='{$ban_ipv4_s}' {$ban_ipv4_e} AND ban_type='0'");
                         }
                     }
                 }
                 $db->optimize_table($prefix . '_security');
                 URL::redirect(URL::admin('&amp;ips'));
             }
             $ip = $ip2 = false;
             if (!empty($_POST['ban_ipv4_s'])) {
                 # y.y.y.y/cidr?
                 if ($ip = NET::ipv4_cidr($_POST['ban_ipv4_s'])) {
                     switch ($ip) {
                         case is_array($ip):