Function ipInRangeWithPhpRaw

@author: 713uk13m <dev@nguyenanhung.com>
@time  : 9/20/18 14:38

@param string $ip
@param string $range

@return bool
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));
    }
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;
    }
1122064
public static function inRange(string $ip, string $range): bool
	{
		if(strpos($range, '/') === false)
		{
			$netmask = 32;
		}
		else
		{
			[$range, $netmask] = explode('/', $range, 2);

			if($netmask < 0 || $netmask > 32)
			{
				return false;
			}
		}

		if(($ip2Long = ip2long($ip)) === false || ($range2Long = ip2long($range)) === false)
		{
			return false;
		}

		$netmaskDecimal = ~ ((2 ** (32 - $netmask)) - 1);

		return ($ip2Long & $netmaskDecimal) === ($range2Long & $netmaskDecimal);
	}
84474
public function getPageRange($range = 4)
    {
        $from = max(1, $this->getPage() - $range);
        $to = min($this->getPageCount(), $this->getPage() + $range);

        return range($from, $to);
    }
554453
public static function ip_in_range(string $ip, $min, $max=null) {
		ref\sanitize::ip($ip, true);
		if (! \is_string($min)) {
			return false;
		}

		// Bad IP.
		if (! $ip) {
			return false;
		}

		// Is $min a range?
		if (false !== \strpos($min, '/')) {
			if (false === ($range = format::cidr_to_range($min))) {
				return false;
			}
			$min = $range['min'];
			$max = $range['max'];
		}
		// Max is required otherwise.
		elseif (null === $max) {
			return false;
		}

		// Convert everything to a number.
		ref\format::ip_to_number($ip);
		ref\format::ip_to_number($min);
		ref\format::ip_to_number($max);

		if (
			(false !== $ip) &&
			(false !== $min) &&
			(false !== $max)
		) {
			return static::in_range($ip, $min, $max);
		}

		return false;
	}
493058
public function validateIpAddress(string $ipAddress) : bool
    {
        if ($ipAddress === '') {
            return false;
        }

        return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE);
    }
493558
public static function isLocal(string $ip = null)
    {
        if (is_null($ip)) {
            $ip = self::get();
        }

        if (stripos($ip, '127.') !== false) {
            return true;
        }

        return !(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) == $ip);
    }
375325
public function ipInRange($ip_address = '', $network_range = '')
    {
        $ip_address    = trim($ip_address);
        $network_range = trim($network_range);
        if (empty($ip_address) || empty($network_range)) {
            return NULL;
        }
        try {
            $address = \IPLib\Factory::addressFromString($ip_address);
            $range   = \IPLib\Factory::rangeFromString($network_range);
            $result  = $address->matches($range);

            return $result;
        }
        catch (\Exception $e) {
            return 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
        }
    }
116808
public boolean inRange(InetAddress ip) {
        if (greaterThan(ip, ipHigher))
            return false;
        else if (lessThan(ip, ipLower))
            return false;
        else
            return true;
    }
410390
public function removeAllowed ($range)
	{
		
		$formatted	= $this->formatRange ($range);
		
		if (!$formatted)
		{
			return FALSE;
		}
		
		unset ($this->allowIPs[$formatted[0]]);
		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]);
        }
    }
35749
public function range($range = null)
    {
        if (!func_num_args()) {
            return $this->_start . '-' . ($this->_limit ? $this->_start + $this->_limit : '');
        }
        $values = explode('-', $range);
        $this->_start = (int) $values[0];
        $this->_limit = $values[1] !== '' ? $values[1] - $values[0] : null;
        return $this;
    }
1003044
protected function parseRangeUsingCidr($input, &$range): void
    {
        $input = explode('/', $input);
        $this->fillAddress($input[0], '0');

        $range['min'] = $input[0];
        $isAddressMask = strpos($input[1], '.') !== false;

        if ($isAddressMask && $this->verifyAddress($input[1])) {
            $range['mask'] = sprintf('%032b', ip2long($input[1]));
            return;
        }

        if ($isAddressMask || $input[1] < 8 || $input[1] > 30) {
            throw new ComponentException('Invalid network mask');
        }

        $range['mask'] = sprintf('%032b', ip2long(long2ip(~(2 ** (32 - $input[1]) - 1))));
    }
1283664
def ip_between(ip, start, finish):
    """"""

    if is_IPv4Address(ip) and is_IPv4Address(start) and is_IPv4Address(finish):
        return IPAddress(ip) in IPRange(start, finish)
    else:
        return False
1100915
public boolean belowRange(InetAddress ip) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "belowRange, ip is " + ip);
            Tr.debug(tc, "belowRange, ipLower is " + ipLower);
        }
        return lessThan(ip, ipLower);
    }
466630
public function checkPermission($ip, $context)
    {
        if (!is_string($ip)) {
            throw new \TypeError('The ip parameter must be a string.');
        }
        if (!$ip) {
            throw new \InvalidArgumentException('The ip parameter cannot be empty.');
        }

        $currentRequest = $this->requestStack->getCurrentRequest();

        if (!$currentRequest) {
            return false;
        }

        return IpUtils::checkIp($currentRequest->getClientIp(), $ip);
    }
297612
private function parseCidrRange($range)
    {
        list($address, $mask) = explode('/', $range);
        $longAddress = ip2long($address);
        return array(
            $longAddress & (((1 << $mask) - 1) << (32 - $mask)),
            $longAddress | ((1 << (32 - $mask)) - 1)
        );
    }