Checks whether the given string is a valid public IPv4 or IPv6 address

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

        return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE);
    }
352359
public function ifIsIpAddress()
    {
        if ($this->value->isIpAddress()) {
            return $this->value->value();
        }

        $this->paramErrors->append($this->paramName, 'INVALID_IP_ADDRESS');
        return null;
    }
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;
    }
689274
public function isIpWhitelisted($ipAddress)
    {
        // determine whether this IP is IPv4 or IPv6
        $isIpv4Address = filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
        return $this->isIpInWhitelist(
            ($isIpv4Address) ? $this->ipv4Whitelist : $this->ipv6Whitelist,
            $ipAddress
        );
    }
1261297
public function checkIpIsPrivate($ipGiven)
    {
        if (filter_var($ipGiven, FILTER_VALIDATE_IP)) {
            if (!filter_var($ipGiven, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE)) {
                return 'private';
            }
            return 'public';
        }
        return 'invalid IP';
    }
1267084
public static function isIpV6Address($value): bool
    {
        if (!static::isStringCastable($value)) {
            return false;
        }

        return filter_var((string) $value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
    }
499140
public static function reverseIpv4(string $address): bool
    {
        $pattern = '/^((?:[0-9]+\.){1,4})in\-addr\.arpa\.$/i';

        if (1 !== preg_match($pattern, $address, $matches)) {
            return false;
        }

        $octets = explode('.', $matches[1]);
        array_pop($octets); //Remove the last decimal from the array

        foreach ($octets as $octet) {
            if ((int) $octet > 255) {
                return false;
            }
        }

        return true;
    }
503633
public static function isIP($address)
    {

        //Split the IP address of the form  into parts
        $parts = explode('.', $address);
        //=4 parts
        if (sizeof($parts) != 4) {
            return false;
        }
        foreach ($parts as $part):
            if (empty($part) || !static::number($part) || $part > 255) {
                return false;
            }
        endforeach;

        return true;
    }
16341
private function isTrustedIpAddress($ipAddress)
    {
        foreach ($this->trustedIpRanges as $trustedIpBlock) {
            if ($trustedIpBlock->containsIP($ipAddress)) {
                return true;
            }
        }

        return false;
    }
228247
function ispublic($addr) {
		return (bool)filter_var($addr,FILTER_VALIDATE_IP,
			FILTER_FLAG_IPV4|FILTER_FLAG_IPV6|
			FILTER_FLAG_NO_PRIV_RANGE|FILTER_FLAG_NO_RES_RANGE);
	}
883257
def is_valid_ipv6 (ip):
    
    # XXX this is not complete: check ipv6 and ipv4 semantics too here
    if not (_ipv6_re.match(ip) or _ipv6_ipv4_re.match(ip) or
            _ipv6_abbr_re.match(ip) or _ipv6_ipv4_abbr_re.match(ip)):
        return False
    return True
159478
public function ipAddress($subject) : bool
    {
        if ($subject === null) {
            return false;
        }
        $v = '' . $subject;
        return $v === '' ? false : !!filter_var($v, FILTER_VALIDATE_IP);
    }
460303
public function ipToHex($ipAddress)
    {
        $hex = '';
        if (strpos($ipAddress, ',') !== false) {
            $splitIp = explode(',', $ipAddress);
            $ipAddress = trim($splitIp[0]);
        }
        $isIpV6 = false;
        $isIpV4 = false;
        if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) {
            $isIpV6 = true;
        } elseif (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) {
            $isIpV4 = true;
        }
        if (!$isIpV4 && !$isIpV6) {
            return false;
        }
        // IPv4 format
        if ($isIpV4) {
            $parts = explode('.', $ipAddress);
            for ($i = 0; $i < 4; $i++) {
                $parts[ $i ] = str_pad(dechex($parts[ $i ]), 2, '0', STR_PAD_LEFT);
            }
            $ipAddress = '::'.$parts[0].$parts[1].':'.$parts[2].$parts[3];
            $hex = implode('', $parts);
        } // IPv6 format
        else {
            $parts = explode(':', $ipAddress);
            // If this is mixed IPv6/IPv4, convert end to IPv6 value
            if (filter_var($parts[ count($parts) - 1 ], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) {
                $partsV4 = explode('.', $parts[ count($parts) - 1 ]);
                for ($i = 0; $i < 4; $i++) {
                    $partsV4[ $i ] = str_pad(dechex($partsV4[ $i ]), 2, '0', STR_PAD_LEFT);
                }
                $parts[ count($parts) - 1 ] = $partsV4[0].$partsV4[1];
                $parts[] = $partsV4[2].$partsV4[3];
            }
            $numMissing = 8 - count($parts);
            $expandedParts = [];
            $expansionDone = false;
            foreach ($parts as $part) {
                if (!$expansionDone && $part == '') {
                    for ($i = 0; $i <= $numMissing; $i++) {
                        $expandedParts[] = '0000';
                    }
                    $expansionDone = true;
                } else {
                    $expandedParts[] = $part;
                }
            }
            foreach ($expandedParts as &$part) {
                $part = str_pad($part, 4, '0', STR_PAD_LEFT);
            }
            $ipAddress = implode(':', $expandedParts);
            $hex = implode('', $expandedParts);
        }
        // Validate the final IP
        if (!filter_var($ipAddress, FILTER_VALIDATE_IP)) {
            return false;
        }

        return strtolower(str_pad($hex, 32, '0', STR_PAD_LEFT));
    }
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;
    }
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;
		}
	}
663969
private function isIpInWhitelist(array $whitelist, $ipAddress)
    {
        foreach ($whitelist as $ipRange) {
            if ($ipRange->containsIp($ipAddress)) {
                return true;
            }
        }
        return false;
    }
85801
public static IPAddressType getAddressType(String ipAddress)
    {
    	if(IPAddressUtil.isIPv4LiteralAddress(ipAddress))
    		return IPAddressType.IPV4;
    	
    	if(IPAddressUtil.isIPv6LiteralAddress(ipAddress))
    		return IPAddressType.IPV6;
    	
    	return IPAddressType.INVALID;
    }