ip2long example



        return true;
    }

    /** * Validates an IPv4 address * * @param string $value */
    protected function _validateIPv4($value) {
        $ip2long = ip2long($value);
        if($ip2long === false) {
            return false;
        }

        return $value == long2ip($ip2long);
    }

    /** * Validates an IPv6 address * * @param string $value Value to check against * @return boolean True when $value is a valid ipv6 address * False otherwise */
return self::setCacheResult($cacheKey, false !== filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4));
            }

            if ($netmask < 0 || $netmask > 32) {
                return self::setCacheResult($cacheKey, false);
            }
        } else {
            $address = $ip;
            $netmask = 32;
        }

        if (false === ip2long($address)) {
            return self::setCacheResult($cacheKey, false);
        }

        return self::setCacheResult($cacheKey, 0 === substr_compare(sprintf('%032b', ip2long($requestIp))sprintf('%032b', ip2long($address)), 0, $netmask));
    }

    /** * Compares two IPv6 addresses. * In case a subnet is given, it checks if it contains the request IP. * * @author David Soria Parra <dsp at php dot net> * * @see https://github.com/dsp/v6tools * * @param string $ip IPv6 address or subnet in CIDR notation * * @throws \RuntimeException When IPV6 support is not enabled */
$host      = self::API_HOST;
        $api_key   = self::get_api_key();

        if ( $api_key ) {
            $request = add_query_arg( 'api_key', $api_key$request );
        }

        $http_host = $host;
        // use a specific IP if provided         // needed by Akismet_Admin::check_server_connectivity()         if ( $ip && long2ip( ip2long( $ip ) ) ) {
            $http_host = $ip;
        }

        $http_args = array(
            'body' => $request,
            'headers' => array(
                'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),
                'Host' => $host,
                'User-Agent' => $akismet_ua,
            ),
            'httpversion' => '1.0',
            
return self::setCacheResult($cacheKey, false !== filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4));
            }

            if ($netmask < 0 || $netmask > 32) {
                return self::setCacheResult($cacheKey, false);
            }
        } else {
            $address = $ip;
            $netmask = 32;
        }

        if (false === ip2long($address)) {
            return self::setCacheResult($cacheKey, false);
        }

        return self::setCacheResult($cacheKey, 0 === substr_compare(sprintf('%032b', ip2long($requestIp))sprintf('%032b', ip2long($address)), 0, $netmask));
    }

    /** * Compares two IPv6 addresses. * In case a subnet is given, it checks if it contains the request IP. * * @author David Soria Parra <dsp at php dot net> * * @see https://github.com/dsp/v6tools * * @param string $ip IPv6 address or subnet in CIDR notation * * @throws \RuntimeException When IPV6 support is not enabled */
if(!is_long($port)) {
            $this->verbose=true;
            $this->SendMSG("Incorrect port syntax");
            return FALSE;
        } else {
            $ip=@gethostbyname($host);
            $dns=@gethostbyaddr($host);
            if(!$ip) $ip=$host;
            if(!$dns) $dns=$host;
            // Validate the IPAddress PHP4 returns -1 for invalid, PHP5 false             // -1 === "255.255.255.255" which is the broadcast address which is also going to be invalid             $ipaslong = ip2long($ip);
            if ( ($ipaslong == false) || ($ipaslong === -1) ) {
                $this->SendMSG("Wrong host name/address \"".$host."\"");
                return FALSE;
            }
            $this->_host=$ip;
            $this->_fullhost=$dns;
            $this->_port=$port;
            $this->_dataport=$port-1;
        }
        $this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\"");
        if($reconnect){
            


        // Check for a direct match         if ((string) $host === (string) $reference) {
            return true;
        }

        // Calculate the valid wildcard match if the host is not an IP address         // Also validates that the host has 3 parts or more, as per Firefox's ruleset,         // as a wildcard reference is only allowed with 3 parts or more, so the         // comparison will never match if host doesn't contain 3 parts or more as well.         if (ip2long($host) === false) {
            $parts    = explode('.', $host);
            $parts[0] = '*';
            $wildcard = implode('.', $parts);
            if ($wildcard === (string) $reference) {
                return true;
            }
        }

        return false;
    }
}
Home | Imprint | This part of the site doesn't use cookies.