returns True if the $ip is defined

@param  string  $host

@return boolean
546691
public function hasIp($ip)
    {
        $this->processFile($this->getFile());

        return array_key_exists($ip, $this->ips);
    }
1147593
private static boolean isIPv6Addr(String host) {
        if (host != null) {
            if (host.contains("[") && host.contains("]"))
                host = host.substring(host.indexOf("[") + 1, host.indexOf("]"));
            host = host.toLowerCase();
            Pattern p1 = Pattern.compile("^(?:(?:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9](?::|$)){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))$");
            Pattern p2 = Pattern.compile("^(\\d{1,3}\\.){3}\\d{1,3}$");
            Matcher m1 = p1.matcher(host);
            boolean b1 = m1.matches();
            Matcher m2 = p2.matcher(host);
            boolean b2 = !m2.matches();
            return b1 && b2;
        } else {
            return false;
        }
    }
675980
public function hasHost(string $host): bool
	{
		$host = Host::filter($host);
		return $this->offsetExists($host);
	}
1051018
public function isLinked(string $host = null): bool
    {
        // link exists?
        // e.g: isLinked('localhost')
        if ($host && isset($this->links[$host])) {
            return ($this->links[$host]->status() === Link::STATUS_CONNECTED);
        }

        // without master/slave directives
        // e.g: isLinked()
        if (true !== $this->config->get('sharding')) {
            foreach ($this->links as $link) {
                return ($link->status() === Link::STATUS_CONNECTED);
            }
        }

        // with master/slave directives, check by host
        switch (trim((string) $host)) {
            // e.g: isLinked(), isLinked('master')
            case '':
            case Link::TYPE_MASTER:
                foreach ($this->links as $link) {
                    if ($link->getType() == Link::TYPE_MASTER) {
                        return ($link->status() === Link::STATUS_CONNECTED);
                    }
                }
                break;
            // e.g: isLinked('slave1.mysql.local'), isLinked('slave')
            case Link::TYPE_SLAVE:
                foreach ($this->links as $link) {
                    if ($link->getType() == Link::TYPE_SLAVE) {
                        return ($link->status() === Link::STATUS_CONNECTED);
                    }
                }
                break;
        }

        return false;
    }
193112
protected function matchIp(/*# string */ $ip, array $patterns)/*# : bool */
    {
        $num = ip2long($ip);
        foreach ($patterns as $pat) {
            if (($num & $pat[1]) == $pat[0]) {
                return true;
            }
        }
        return false;
    }
1345182
public static function setHost($host) {

		if(false === is_string($host)) {
  			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($host)), E_USER_ERROR);
  		}

		$_SERVER['HTTP_HOST'] = $host;
	}
1125585
public function is_ip(bool $restricted=true) {
		if (! $this->is_valid()) {
			return false;
		}

		if ($restricted) {
			return !! \filter_var($this->host, \FILTER_VALIDATE_IP);
		}

		return !! \filter_var(
			$this->host,
			\FILTER_VALIDATE_IP,
			\FILTER_FLAG_NO_PRIV_RANGE | \FILTER_FLAG_NO_RES_RANGE
		);
	}
395065
protected function isValidIpAddress($ip)
    {
        $flags = FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6;
        if (filter_var($ip, FILTER_VALIDATE_IP, $flags) === false) {
            return false;
        }
        return true;
    }
535192
public static boolean isInetAddress(String host) {
		int colons = 0;
		int dots = 0;
		byte[] bytes = encodeAscii(host);

		// expect ipv6 address
		if (bytes[0] == '[') {
			return bytes[bytes.length - 1] == ']' && checkIpv6(bytes, 1, bytes.length - 1);
		}

		// assume ipv4 could be as oct, bin, dec; ipv6 - hex
		for (byte b : bytes) {
			if (b == '.') {
				dots++;
			} else if (b == ':') {
				if (dots != 0) {
					return false;
				}
				colons++;
			} else if (Character.digit(b, 16) == -1) {
				return false;
			}
		}

		if (dots < 4) {
			if (colons > 0 && colons < 8) {
				return checkIpv6(bytes, 0, bytes.length);
			}
			return checkIpv4(bytes, 0, bytes.length);
		}
		return false;
	}
493558
public static function isLocal(string $ip = null)
    {
        if (is_null($ip)) {
            $ip = self::get();
        }

        if (stripos($ip, '127.') !== false) {
            return true;
        }

        return !(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) == $ip);
    }
493145
public function hostMatches($host)
    {
        $pattern = '@^' . str_replace('\*', '.*', preg_quote($this->options['_host'], '@')) . '$@';

        return preg_match($pattern, $host) !== 0;
    }
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;
    }
1181509
public static function isHostnameIP($hostname)
  {
    // IP-literal: encased in square brackets
    // we match starting [ character followed by non ] characters followed by ] character as last character in hostname
    if(preg_match('/^\[[^\]]\]$/',$hostname)){
      // ok its an IP-literal, we do not parse the literal to see if its valid
      return true;
    }
    // IPv4 in decimal
    if(preg_match('/^[0-9]+$/',$hostname)){
      // ok its a number
      // lets see if its in the 32bit range
      $ip4_hex=base_convert($hostname, 10, 16);
      if(strlen($ip4_hex)<=8){
        // ok, hex representation is less than 9 chars, so thats max FFFFFFFF
        return true;
      }
    }
    $ip_parts=Array();
    if(!preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/',$hostname,$ip_parts)){
      return false;
    }
    // check if each block is in byte range (hard to test with regex)
    for($j=1;$j<=4;$j++){
      if(($ip_parts[$j]>255) || ($ip_parts[$j]<0)){
        return false;
      }
    }
    return true;
  }
799189
public function setHost($host)
    {
        if ($host instanceof $this->hostClass || $host instanceof \yii\web\IdentityInterface) {
            return $this->{$this->createdByAttribute} = $host->getGUID();
        }
        if (is_string($host) && preg_match(Number::GUID_REGEX, $host)) {
            return $this->{$this->createdByAttribute} = Number::guid_bin($host);
        }
        if (strlen($host) == 16) {
            return $this->{$this->createdByAttribute} = $host;
        }
        return false;
    }
1359934
private function isValid($ip)
    {
        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
            && !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE)
        ) {
            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;
    }
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;
    }