Checks if a given range is within a range

@param $ipAndCidrSub
@param $ipAndCidrSuper
@return bool
12616
static public function IsIPv4SubnetWithinSupernet($ipAndCidrSub, $ipAndCidrSuper)
    {

        $ipAndCidrSubMin   = static::ConvertIPv4ToDecimal(
            static::GetIPv4NetworkAddress($ipAndCidrSub)
        );

        $ipAndCidrSubMax   = static::ConvertIPv4ToDecimal(
            static::GetIPv4BroadcastAddress($ipAndCidrSub)
        );

        $ipAndCidrSuperMin   = static::ConvertIPv4ToDecimal(
            static::GetIPv4NetworkAddress($ipAndCidrSuper)
        );

        $ipAndCidrSuperMax   = static::ConvertIPv4ToDecimal(
            static::GetIPv4BroadcastAddress($ipAndCidrSuper)
        );

        if ($ipAndCidrSuperMin <= $ipAndCidrSubMin && $ipAndCidrSuperMax >= $ipAndCidrSubMax) {
            return true;
        }

        return false;

    }
84587
static public function ConvertIPv4CIDRToDecimal($ipAndCidr)
    {

        list($ip, $subnetMask) = explode("/", $ipAndCidr);

        $ip = static::ConvertIPv4ToDecimal($ip);

        $subnetMask = static::ConvertIPv4CIDRToMask($subnetMask);

        $subnetMask = static::ConvertIPv4ToDecimal($subnetMask);

        return compact('ip', 'subnetMask');

    }
573350
private boolean isSoilAnalysisExist(ArrayList<HashMap> icSubArr) {

        for (HashMap icSubData : icSubArr) {
            if (!getValueOr(icSubData, "slsc", "").equals("")) {
                return true;
            }
        }
        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;
	}
533294
public function isSubdomainExists( $subdomain, $excludeId = null )
    {
        return $this->isExists( empty( $excludeId ) ? array(
            'subdomain' => $subdomain,
        ) : array(
            'subdomain' => $subdomain,
            new Predicate\Operator(
                'id',
                Predicate\Operator::OP_NE,
                $excludeId
            ),
        ) );
    }
48533
public static function isIpInCidr(string $ip, string $cidr): bool
    {
        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            throw new \UnexpectedValueException(
                "invalid value for ip; expecting an IPv4 address"
            );
        }

        list($range, $netmask) = static::parseCidr($cidr);
        $netmask = ~((1 << (32 - $netmask)) - 1);
        return ((ip2long($ip) & $netmask) === ip2long($range));
    }
1307809
public boolean contains(long startDrId, long endDrId) {
        assert startDrId <= endDrId;
        return endDrId <= getSafePointDrId() || m_map.encloses(range(startDrId, endDrId));
    }
4934
public function isIPAddressInSubnet($ip_address_string)
    {
        $ip_address = ip2long($ip_address_string);
        list($start_ip, $end_ip) = $this->getIPAddressRangeAsInts();

        return $ip_address >= $start_ip && $ip_address <= $end_ip
            ? true
            : false;
    }
766582
public static function isIpLocal($ipAddr)
	{
		// $this->debug->groupCollapsed(__CLASS__.'->'.__FUNCTION__, $ip);
		$return = false;
		if ($ipAddr == '::1') {
			$ipAddr = '127.0.0.1';
		}
		$net_n_masks = array(
			array('127.0.0.0',		'255.0.0.0'),
			array('10.0.0.0',		'255.0.0.0'),
			array('192.168.0.0',	'255.255.0.0'),
			array('172.16.0.0',		'255.240.0.0'),
			array('169.254.0.0',	'255.255.0.0'),
		);
		foreach ($net_n_masks as $nma) {
			if (self::isIpIn($ipAddr, $nma[0], $nma[1])) {
				$return = true;
				break;
			}
		}
		// $this->debug->groupEnd();
		return $return;
	}
1036862
public function isPageRestricted($siteId, $pageType, $pageName, $privilege)
    {
        return $this->isPageRestricted->__invoke(
            $siteId,
            $pageType,
            $pageName,
            $privilege
        );
    }
705529
protected boolean ipInRange(String ipAddress, String range) {
        IpAddressMatcher addressMatcher = new IpAddressMatcher(range);
        return addressMatcher.matches(ipAddress);
    }
832455
public function isInsideSubTreeLimit()
    {
        /** @var eZTagsObject[] $path */
        $path = $this->getPath( true, true );

        if ( is_array( $path ) && !empty( $path ) )
        {
            foreach ( $path as $tag )
            {
                if ( $tag->getSubTreeLimitationsCount() > 0 )
                    return true;
            }
        }

        return false;
    }
866979
protected static function cidrMatch64bit($ipAddr, $cidr)
    {
        list ($sn, $bits) = explode('/', $cidr);
        $ipLong = self::ip2long64($ipAddr, $bits);
        $subnet = self::ip2long64($sn, $bits);
        $mask = -1 << (32 - $bits);

        return ($ipLong & $mask) == $subnet;
    }
160777
public static function getSomeIpsFromRange($ipSubnet, $number = 3)
    {
        list($start, $end) = self::getIpRangeForSubnet($ipSubnet);

        $longStart = ip2long($start);
        $diff = ip2long($end) - $longStart;
        $parts = round($diff / ($number + 1));

        $ips = [];
        for ($x = 1; $x <= $number; $x++) {
            $ips[] = long2ip($longStart + ($parts * $x));
        }

        return $ips;
    }
1323923
static public function GetIPv4NumberOfHostAddresses($ipAndCidr)
    {

        $ipAndCidrNetwork   = static::ConvertIPv4ToDecimal(
            static::GetIPv4NetworkAddress($ipAndCidr)
        );


        $ipAndCidrBroadcast = static::ConvertIPv4ToDecimal(
            static::GetIPv4BroadcastAddress($ipAndCidr)
        );

        return $ipAndCidrBroadcast - $ipAndCidrNetwork - 1;

    }
840910
public static function mapXDomainUser($domain_username, $domain, $uidNumber)
	{
		$db = \App::get('db');

		if (empty($domain))
		{
			return 0;
		}

		$query = 'SELECT domain_id FROM `#__xdomains` WHERE ' .
				 '#__xdomains.domain=' . $db->quote($domain);

		$db->setQuery($query);

		$result = $db->loadObject();

		if (empty($result))
		{
			$query = 'INSERT INTO `#__xdomains` (domain) VALUES (' . $db->quote($domain) . ')';

			$db->setQuery($query);

			$db->query();

			$domain_id = $db->insertid();
		}
		else
		{
			$domain_id = $result->domain_id;
		}

		$query = 'INSERT INTO `#__xdomain_users` (domain_id,domain_username,uidNumber) ' .
			' VALUES (' . $db->quote($domain_id) . ',' .
			$db->quote($domain_username) . ',' . $db->quote($uidNumber) . ')';

		$db->setQuery($query);

		if (!$db->query())
		{
			return false;
		}

		return true;
	}
18222
public static function isInRange(string $range, string $ip) : bool
    {
        if (strpos($range, '/') !== false) {
            // $range is in IP/NETMASK format
            list($range, $netmask) = explode('/', $range, 2);
            if (strpos($netmask, '.') !== false) {
                // $netmask is a 255.255.0.0 format
                $netmask = str_replace('*', '0', $netmask);
                $netmask_dec = ip2long($netmask);

                return (ip2long($ip) & $netmask_dec) == (ip2long($range) & $netmask_dec);
            } else {
                // $netmask is a CIDR size block
                // fix the range argument
                $x = explode('.', $range);
                while (count($x) < 4) {
                    $x[] = '0';
                }
                list($a, $b, $c, $d) = $x;
                $range = sprintf(
                    '%u.%u.%u.%u',
                    empty($a) ? '0' : $a,
                    empty($b) ? '0' : $b,
                    empty($c) ? '0' : $c,
                    empty($d) ? '0' : $d
                );
                $range_dec = ip2long($range);
                $ip_dec = ip2long($ip);

                // Strategy 1 - Create the netmask with 'netmask' 1s and then fill it to 32 with 0s
                //$netmask_dec = bindec(str_pad('', $netmask, '1') . str_pad('', 32-$netmask, '0'));

                // Strategy 2 - Use math to create it
                $wildcard_dec = pow(2, (32 - $netmask)) - 1;
                $netmask_dec = ~$wildcard_dec;

                return ($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec);
            }
        } else {
            // range might be 255.255.*.* or 1.2.3.0-1.2.3.255
            if (strpos($range, '*') !== false) { // a.b.*.* format
                // Just convert to A-B format by setting * to 0 for A and 255 for B
                $lower = str_replace('*', '0', $range);
                $upper = str_replace('*', '255', $range);
                $range = "$lower-$upper";
            }

            if (strpos($range, '-') !== false) { // A-B format
                list($lower, $upper) = explode('-', $range, 2);
                $lower_dec = (float) sprintf('%u', ip2long($lower));
                $upper_dec = (float) sprintf('%u', ip2long($upper));
                $ip_dec = (float) sprintf('%u', ip2long($ip));

                return ($ip_dec >= $lower_dec) && ($ip_dec <= $upper_dec);
            }

            throw new \InvalidArgumentException(
                sprintf("Invalid range '%s', not in format 1.2.3.4/24 or 1.2.3.4/255.255.255.0", $range)
            );
        }
    }