Check if ip is within range.

@param string $cidr
@param string $ip

@return bool
763386
public static function contains($cidr, $ip)
    {
        $cidr = Range::parse($cidr);

        $ip = new IP($ip);

        if ($cidr->getFirstIP()->getVersion() !== $ip->getVersion()) {
            return false;
        }

        return $cidr->contains($ip);
    }
193112
protected function matchIp(/*# string */ $ip, array $patterns)/*# : bool */
    {
        $num = ip2long($ip);
        foreach ($patterns as $pat) {
            if (($num & $pat[1]) == $pat[0]) {
                return true;
            }
        }
        return false;
    }
723620
public static function validateIP($ip) {
        if (strtolower($ip) === 'unknown')
            return false;

        // generate ipv4 network address
        $ip = ip2long($ip);

        // if the ip is set and not equivalent to 255.255.255.255
        if ($ip !== false && $ip !== -1) {
            // make sure to get unsigned long representation of ip
            // due to discrepancies between 32 and 64 bit OSes and
            // signed numbers (ints default to signed in PHP)
            $ip = sprintf('%u', $ip);
            // do private network range checking
            if ($ip >= 0 && $ip <= 50331647)
                return false;
            if ($ip >= 167772160 && $ip <= 184549375)
                return false;
            if ($ip >= 2130706432 && $ip <= 2147483647)
                return false;
            if ($ip >= 2851995648 && $ip <= 2852061183)
                return false;
            if ($ip >= 2886729728 && $ip <= 2887778303)
                return false;
            if ($ip >= 3221225984 && $ip <= 3221226239)
                return false;
            if ($ip >= 3232235520 && $ip <= 3232301055)
                return false;
            if ($ip >= 4294967040)
                return false;
        }
        return true;
    }
116808
public boolean inRange(InetAddress ip) {
        if (greaterThan(ip, ipHigher))
            return false;
        else if (lessThan(ip, ipLower))
            return false;
        else
            return true;
    }
771343
function ipInRangeWithPhpRaw($ip = '', $range = '')
    {
        if (strpos($range, '/') == FALSE) {
            $range .= '/32';
        }
        // $range is in IP/CIDR format eg 127.0.0.1/24
        list($range, $netmask) = explode('/', $range, 2);
        $range_decimal    = ip2long($range);
        $ip_decimal       = ip2long($ip);
        $wildcard_decimal = pow(2, (32 - $netmask)) - 1;
        $netmask_decimal  = ~$wildcard_decimal;

        return (($ip_decimal & $netmask_decimal) == ($range_decimal & $netmask_decimal));
    }
679699
public static function ip(string $value):bool
    {
        $value = (string)$value;
        $valid = filter_var($value, FILTER_VALIDATE_IP);
        return $valid !== false;
    }
1139599
public function containsIp($ipAddress)
    {
        // if the mask is false this means we have a full IP address as a
        // range so compare against the whole string
        if (false === $this->mask) {
            return ($this->rangeSubstring === $this->convertToBinaryString($ipAddress));
        }

        // remove the masked part of the address
        $ipAddressSubstring = substr(
            $this->convertToBinaryString($ipAddress),
            0,
            $this->mask
        );
        return ($this->rangeSubstring === $ipAddressSubstring);
    }
901271
protected function validateIp($ip)
    {
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_IPV6) === false) {
            return false;
        }

        return true;
    }
1061292
public function isValidIP4NoPrivate(string $ipAddress): bool
    {
        return (bool) filter_var(
            $ipAddress,
            FILTER_VALIDATE_IP,
            FILTER_FLAG_IPV4
            | FILTER_FLAG_NO_PRIV_RANGE
            | FILTER_FLAG_NO_RES_RANGE
        );
    }
1182492
public function isValidIP4(string $ipAddress): bool
    {
        return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_RES_RANGE);
    }
1359934
private function isValid($ip)
    {
        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
            && !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE)
        ) {
            return false;
        }

        return true;
    }
1192384
private function ip_is_private($ip)
    {
        $privateAddresses = [ '10.0.0.0|10.255.255.255', '172.16.0.0|172.31.255.255', '192.168.0.0|192.168.255.255', '169.254.0.0|169.254.255.255', '127.0.0.0|127.255.255.255' ];
        $long_ip = ip2long($ip);
        if($long_ip != -1)
        {
            foreach($privateAddresses as $pri_addr)
            {
                list($start, $end) = explode('|', $pri_addr);
                // IF IS PRIVATE
                if($long_ip >= ip2long($start) && $long_ip <= ip2long($end))
                {
                        return true;
                }
            }
        }
        return false;
    }
621085
public function set($ip)
    {
        if (is_long($ip)) {
            $ip = long2ip($ip);
        }

        Assertion::ip($ip);

        $this->callMethod('setip', compact('ip'));

        return true;
    }
347483
public static function isIp($input = false) {

        if ($input && !filter_var($input, FILTER_VALIDATE_IP) === false) {

            return true;
        }

        return false;
    }
1236942
public function ipValidateV4($ip)
    {
        $this->debug->info(__FUNCTION__, 'IP: ' . json_encode($ip));
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE) {
            $this->debug->info(__FUNCTION__, 'Valid is FALSE');

            return FALSE;
        }

        $this->debug->info(__FUNCTION__, 'Valid is TRUE');

        return TRUE;
    }
1111327
private static function assertIpIsValid(string $ip)
    {
        if (preg_match(self::REGEX_IP, $ip) === self::PREG_MATCH_SUCCESS) {
            // Ip address is valid
        } else {
            throw new BunqException(self::ERROR_INVALID_IP_ADDRESS, [$ip]);
        }
    }
697577
public static function ipCidrCheck($p_ip, $p_cidr)
    {
        if (strpos($p_cidr, '/') !== false) {
            list ($net, $mask) = split("/", $p_cidr);
            $ip_net            = ip2long($net);
            $ip_mask           = ~((1 << (32 - $mask)) - 1);
            $ip_ip             = ip2long($p_ip);
            $ip_ip_net         = $ip_ip & $ip_mask;
            
            return ($ip_ip_net == $ip_net);
        } else {
            return (ip2long($p_ip) == ip2long($p_cidr));
        }
    }