Check if given input is a valid IP address.
@param mixed input
@return boolean
347483
public static function isIp($input = false) {

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

            return true;
        }

        return false;
    }
497237
def is_valid_ip(ip_address):
    
    if not ip_address:
        return False
    ip_address = ip_address.strip()
    try:
        validate_ipv46_address(ip_address)
        return True
    except ValidationError:
        return False
643054
public function validate($input): bool
    {
        // for array
        if (\is_array($input)) {
            return \in_array($this->containsValue, $input, true);
        }
        // for string
        if (\is_string($input)) {
            return false !== mb_strpos($input, $this->containsValue, 0, mb_detect_encoding($input));
        }
        return 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;
    }
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;
    }
199796
private static function isValid($input)
    {
        if (!is_array($input)) {
            return false;
        }
        foreach ($input as $value) {
            if (!is_scalar($value)) {
                return false;
            }
        }

        return true;
    }
383959
def validate(self, ip, **kwargs):
        """"""
        
        if ip is None:
            return False

        ip = stringify(ip)

        if self.IPV4_REGEX.match(ip):

            try:
                socket.inet_pton(socket.AF_INET, ip)
                return True
            except AttributeError:  # no inet_pton here, sorry
                try:
                    socket.inet_aton(ip)
                except socket.error:
                    return False
                return ip.count('.') == 3
            except socket.error:  # not a valid address
                return False

        if self.IPV6_REGEX.match(ip):
            try:
                socket.inet_pton(socket.AF_INET6, ip)
            except socket.error:  # not a valid address
                return False
            return True
901271
protected function validateIp($ip)
    {
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_IPV6) === false) {
            return false;
        }

        return true;
    }
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;
    }
811428
public static function ipAddress($ipAddress)
    {
        if (false === filter_var($ipAddress, FILTER_VALIDATE_IP)) {
            throw new InputValidationException('invalid "ip_address"');
        }

        // normalize the IP address (only makes a difference for IPv6)
        return inet_ntop(inet_pton($ipAddress));
    }
301215
public static function isIp($ip, $allowIpV4 = true, $allowIpV6 = true) {
        if ($allowIpV6 && $allowIpV4)
            return \filter_var($ip, FILTER_VALIDATE_IP) !== false;
        if (!$allowIpV6 && $allowIpV4)
            return \filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
        if ($allowIpV6 && !$allowIpV4)
            return \filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
    }
67619
private function validateInputs($ip_address, $network_size)
    {
        if (!filter_var($ip_address, FILTER_VALIDATE_IP)) {
            throw new \UnexpectedValueException("IP address $ip_address not valid.");
        }
        if (($network_size < 1) || ($network_size > 32)) {
            throw new \UnexpectedValueException("Network size $network_size not valid.");
        }
    }
1058244
public function validate($input): bool
    {
        $input = (string)$input;
        // check by regular expression
        if (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $input)
            && preg_match("/^.{1,253}$/", $input)
            && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $input)
        ) {
            // check by DNS record
            if ($this->checkDns) {
                return checkdnsrr($input, 'A');
            }
            return true;
        }
        return false;
    }
182996
private function check($value) {

		$ipv4 = new Ipv4();
		$ipv4 -> setValue($value);

		$ipv6 = new Ipv6();
		$ipv6 -> setValue($value);

		return true === $ipv4 -> isValid() || $ipv6 -> isValid();
	}
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));
    }
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;
    }
1139599
public function containsIp($ipAddress)
    {
        // if the mask is false this means we have a full IP address as a
        // range so compare against the whole string
        if (false === $this->mask) {
            return ($this->rangeSubstring === $this->convertToBinaryString($ipAddress));
        }

        // remove the masked part of the address
        $ipAddressSubstring = substr(
            $this->convertToBinaryString($ipAddress),
            0,
            $this->mask
        );
        return ($this->rangeSubstring === $ipAddressSubstring);
    }