Checks if an IP is part of an IP range.

@param string $range IP range specified in one of the following formats:
Wildcard format:     1.2.3.* OR 2001:cdba:0000:0000:0000:0000:3257:*
@return boolean true if IP is part of range, otherwise false.
772766
protected static function processWithAsterisk($range)
    {
        if (strpos($range, '*') !== false) {
            $lowerRange = self::$isv6 ? '0000' : '0';
            $upperRange = self::$isv6 ? 'ffff' : '255';

            $lower = str_replace('*', $lowerRange, $range);
            $upper = str_replace('*', $upperRange, $range);

            $range = $lower . '-' . $upper;
        }

        if (strpos($range, '-') !== false) {
            return self::processWithMinus($range);
        }

        return false;
    }
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;
	}
402318
public function isWhitelisted(AddressInterface $ip = null)
    {
        if ($ip === null) {
            $ip = $this->getRequestIPAddress();
        }
        $rangeType = $this->getRangeType($ip);

        return $rangeType !== null && ($rangeType & static::IPRANGEFLAG_WHITELIST) === static::IPRANGEFLAG_WHITELIST;
    }
1311520
public function containsIP($ip): bool
    {
        if (!$ip instanceof IP) {
            $ip = IP::create($ip);
        }

        return ($ip->numeric() >= $this->getFirstIp()->numeric()) && ($ip->numeric() <= $this->getLastIp()->numeric());
    }
516711
protected function calculateRange(string $range)
	{
		// Remove the "range=" part of the header value

		$range = substr($range, 6);

		// Split the range starting and ending points

		$range = explode('-', $range, 2);

		// Check that the range contains two values

		if(count($range) !== 2)
		{
			return false;
		}

		// Determine start and ending points

		$end = $range[1] === '' ? $this->fileSize - 1 : $range[1];

		if($range[0] === '')
		{
			$start = $this->fileSize - $end;
			$end   = $this->fileSize - 1;
		}
		else
		{
			$start = $range[0];
		}

		$start = (int) $start;
		$end   = (int) $end;

		// Check that the range is satisfiable

		if($start > $end || $end + 1 > $this->fileSize)
		{
			return false;
		}

		// Return the range

		return ['start' => $start, 'end' => $end];
	}
539326
public function clearCellsContents($range)
    {
        if ($range == '')
            throw new Exception('Range not specified');
        
        //Build URI
        $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() . '/worksheets/' . $this->worksheetName . 
                  '/cells/clearcontents?range=' . $range;
        //Sign URI
        $signedURI = Utils::sign($strURI);
        
        //Send request and receive response
        $response = Utils::processCommand($signedURI, 'POST', '', '');
        $json = json_decode($response);
        if ($json->Code == 200)
            return true;
        else
            return false;
    }
382677
public function filterRange($range)
    {
        if (is_int($range)) {
            $level = $range;
            $depth = 0;
        } else {
            reset($range);
            $level = key($range);
            $depth = current($range);
        }

        if (1 === $level) {
            $nodeList = $this->xp->query('/descendant-or-self::*[ name() = "ul" and count( ancestor-or-self::ul ) >= '.$level.'  ]')->item(0);
        } else {
            $nodeList = $this->xp->query('/descendant-or-self::*[ name() = "ul" and count( ancestor-or-self::ul ) >= '.$level.' and ( descendant-or-self::*[ contains(@class, "open") or contains(@class, "active") ] or ancestor-or-self::*[ contains(@class, "open")  or contains(@class, "active") ] ) ]')->item(0);
        }

        if (!$nodeList) {
            return false;
        }

        if (false === $depth) {
            return $nodeList;
        }

        $depthNodelist = $this->xp->query('./descendant::*[ name() = "ul" and count( ancestor-or-self::ul ) > '.($level + $depth).' ]', $nodeList);

        foreach ($depthNodelist as $node) {
            $node->parentNode->removeChild($node);
        }

        if ($nodeList) {
            return $nodeList;
        } else {
            return false;
        }
    }
538462
private function isAllowed($ip) {
        // Look for a wildcard
        if (in_array('*', $this->params['allow'])) {
            // There is a wildcard in the list, all IP's are allowed
            return true;
        }

        // Remove IP's which is not of the same type as $ip before matching
        if ($this->isIPv6($ip)) {
            $list = array_filter($this->params['allow'], [$this, 'isIPv6']);
        } else {
            $list = array_filter($this->params['allow'], [$this, 'isIPv4']);
        }

        foreach ($list as $range) {
            if ((strpos($range, '/') !== false && $this->cidrMatch($ip, $range)) || $ip === $range) {
                return true;
            }
        }

        return false;
    }
555636
public boolean hasIntersection(final Range range) {
		return Math.max(this.start, range.start) <= Math.min(this.end, range.end);
	}
1253881
private function extractNetworkAndMaskFromRange($range)
    {
        if (false !== strpos($range, '/')) {
            // handle the CIDR notation
            list($network, $this->mask) = explode('/', $range);
            // store a substring of the binary representation of the range
            // minus the masked part
            $this->rangeSubstring = substr(
                $this->convertToBinaryString($network),
                0,
                $this->mask
            );
        } else {
            // handle a single IP address
            $this->rangeSubstring = $this->convertToBinaryString($range);
            $this->mask = false;
        }
    }
713434
public function has($name, $range = '') {
        $range = $range ?: $this->range;

        return isset($this->lang[$range][$name]);
    }
84474
public function getPageRange($range = 4)
    {
        $from = max(1, $this->getPage() - $range);
        $to = min($this->getPageCount(), $this->getPage() + $range);

        return range($from, $to);
    }
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;
    }
108832
public static function has($name, $range = null)
    {
        static::_init();
        
        $range = $range ?: self::$range;
        
        $exists = isset(self::$data[$range][$name]) ? true : false;
        
        if (!$exists) {
            $names = explode('.', $name, 3);
            $count = count($names);
            if ($count >= 1) {
                $exists = array_key_exists($names[0], array_keys(self::$data[$range]));
                
                if ($count >= 2 && $exists) {
                    $exists = isset(self::$data[$range][$names[0]]) && array_key_exists($names[1], array_keys(self::$data[$range][$names[0]]));
                }
                
                if ($count >= 3 && $exists) {
                    $exists = isset(self::$data[$range][$names[0]][$names[1]]) && array_key_exists($names[2], array_keys(self::$data[$range][$names[0]][$names[1]]));
                }
            }
        }
        
        return $exists;
    }
1011972
public static function ip_match($ip, $match)
    {
        if (ip2long($match)) {//is an actual IP
            if ($ip == $match) {
                return true;
            }
        } else {//is something weird
            if (strpos($match, '/')) {//if it's a cidr notation
                if (self::cidr_match($ip, $match)) {
                    return true;
                }
            } else {//is a random string (let's say a host name)
                $match = gethostbyname($match);
                if ($ip == $match) {
                    return true;
                } else {
                    return false;
                }
            }
        }
        return false;
    }
1071487
public function getValue($range)
    {
        $range = $range == 'min' ? $range : 'max';

        if (is_null($this->{$range})) {
            $this->{$range} = $this->getFirst($range);
        }

        return $this->{$range};
    }
689128
public function validateIp($ip)
    {
        $ipnums = explode(".", $ip);
        if (count($ipnums) != 4) {
            return false;
        }
        foreach($ipnums as $ipnum) {
            if (!is_numeric($ipnum) || ($ipnum > 255)) {
                return false;
            }
        }
        return $ip;
    }