Checks if an IP is local

@param  string  $ip IP
@return boolean     true if the IP is local, otherwise false
332840
public static function isLocal($ip)
    {
        $localIpv4Ranges = array(
            '10.*.*.*',
            '127.*.*.*',
            '192.168.*.*',
            '169.254.*.*',
            '172.16.0.0-172.31.255.255',
            '224.*.*.*',
        );

        $localIpv6Ranges = array(
            'fe80::/10',
            '::1/128',
            'fc00::/7'
        );

        if (self::isValidv4($ip)) {
            return self::match($ip, $localIpv4Ranges);
        }

        if (self::isValidv6($ip)) {
            return self::match($ip, $localIpv6Ranges);
        }

        return false;
    }
660101
public function isBlacklisted(AddressInterface $ip = null)
    {
        if ($ip === null) {
            $ip = $this->getRequestIPAddress();
        }
        $rangeType = $this->getRangeType($ip);

        return $rangeType !== null && ($rangeType & static::IPRANGEFLAG_BLACKLIST) === static::IPRANGEFLAG_BLACKLIST;
    }
211950
private function isInProxiedIps(string $ip): bool
    {
        foreach ($this->proxyIps as $proxyIp) {
            if ($ip === $proxyIp || self::isInCIDR($ip, $proxyIp)) {
                return true;
            }
        }
        return false;
    }
281176
protected function authIps($userIp)
    {
        if (empty($this->ips)) {
            return true;
        }

        foreach ($this->ips as $ip) {
            if ($userIp === $ip) {
                return true;
            }
        }

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

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

            return true;
        }

        return 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;
	}
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());
    }
437277
public static function check_ipv6($ip)
	{
		$ip = self::uncompress($ip);
		list($ipv6, $ipv4) = self::split_v6_v4($ip);
		$ipv6 = explode(':', $ipv6);
		$ipv4 = explode('.', $ipv4);
		if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4)
		{
			foreach ($ipv6 as $ipv6_part)
			{
				// The section can't be empty
				if ($ipv6_part === '')
					return false;

				// Nor can it be over four characters
				if (strlen($ipv6_part) > 4)
					return false;

				// Remove leading zeros (this is safe because of the above)
				$ipv6_part = ltrim($ipv6_part, '0');
				if ($ipv6_part === '')
					$ipv6_part = '0';

				// Check the value is valid
				$value = hexdec($ipv6_part);
				if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF)
					return false;
			}
			if (count($ipv4) === 4)
			{
				foreach ($ipv4 as $ipv4_part)
				{
					$value = (int) $ipv4_part;
					if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF)
						return false;
				}
			}
			return true;
		}
		else
		{
			return false;
		}
	}
508906
protected function checkIPv6($UserIP = false)
	{
		// Check if IP present
		if ($UserIP === false)
		{
			return false; // No IP, no search.
		}
		// search for user bot IP-filter definitions in localconfig.php
		if (isset($GLOBALS['DLSTATS']['BOT_IPV6']))
		{
			foreach ($GLOBALS['DLSTATS']['BOT_IPV6'] as $lineleft)
			{
				$network = explode("/", trim($lineleft));
				if (! isset($network[1]))
				{
					$network[1] = 128;
				}
				if ($this->dlstatsIPv6InNetwork($UserIP, $network[0], $network[1]))
				{
					return true; // IP found
				}
			}
		}
		return false;
	}
823020
private static boolean isIPAdressValid(final String ip){

        // InetAddress.getByName() validates 'null' as a valid IP (localhost).
        // we do not want that
        if (hasValue(ip)) {
            return IP_ADDR_PATTERN.matcher(ip).matches();
        }
        return false;
    }
393802
protected static function getIpVersion($ip)
    {
        // Test for IPv4
        if (ip2long($ip) !== false)
        {
            return "IPv4";
        }
         
        // Test for IPv6
        if (substr_count($ip, ":" ) < 2) return false; // ::1 or 2001::0db8
        if (substr_count($ip, "::") > 1) return false; // one allowed
        
        $groups = explode(':', $ip);
        $num_groups = count($groups);
        if (($num_groups > 8) || ($num_groups < 3)) return false;

        $empty_groups = 0;
        foreach ($groups as $group)
        {
            $group = trim($group);
            if (!empty($group) && !(is_numeric($group) && ($group == 0)))
            {
                if (!preg_match('#([a-fA-F0-9]{0,4})#', $group)) return false;
            }
            else
            {
                ++$empty_groups;
            }
        }
		if ($empty_groups < $num_groups)
		{
			return "IPv6";
		}
		return false; // no (valid) IP Address
	}
5928
public function isISOBlocked($ip){
        return $this->db->select($this->getBlockedISOTable(), ['iso' => $this->getIPCountryISO($ip)]);
    }
347022
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;
    }
437197
public static function ip(string $value): bool
    {
        $result = filter_var($value, FILTER_VALIDATE_IP);
        return is_string($result) && $value === $result;
    }
415040
public static function isPrivateIp(string $ip): bool
    {
        foreach (self::PRIVATE_IPV4_RANGES as $range) {
            if (self::isIpInCidr($ip, $range)) {
                return true;
            }
        }

        return false;
    }
302237
public static function safeIp2long($ip) 
    {
        $ip = ip2long($ip);

        // convert signed int to unsigned int if on 32 bit operating system
        if ($ip < 0 && PHP_INT_SIZE == 4) {
            $ip = sprintf("%u", $ip);
        } 

        return $ip;
    }
710909
protected function isLocalNetwork($addr)
    {
        // local network IPv6
        if (strpos($addr, ':') !== false) {
            return strpos($addr, 'fc00::') === 0;
        }

        if (($long = ip2long($addr)) === false) {
            return false;
        }

        return
            ($long >= ip2long('10.0.0.0') && $long <= ip2long('10.255.255.255')) ||
            ($long >= ip2long('172.16.0.0') && $long <= ip2long('172.31.255.255')) ||
            ($long >= ip2long('192.168.0.0') && $long <= ip2long('192.168.255.255'))
        ;
    }