Checks if smtp host is valid (tries to connect to it)

@param string $smtpHost currently used smtp server host name

@return bool
549408
protected function _isValidSmtpHost($smtpHost)
    {
        $isSmtp = false;
        if ($smtpHost) {
            $match = [];
            $smtpPort = isset($this->SMTP_PORT)
                ? $this->SMTP_PORT
                : $this->smtpPort;
            if (Str::getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $smtpHost, $match)) {
                $smtpHost = $match[1];
                if (isset($match[3]) && (int) $match[3] !== 0) {
                    $smtpPort = (int) $match[3];
                }
            }
            if ($isSmtp = (bool) ($rHandle = @fsockopen($smtpHost, $smtpPort, $errNo, $errStr, 30))) {
                // closing connection ..
                fclose($rHandle);
            }
        }

        return $isSmtp;
    }
8030
protected function setHost($host)
    {
        $host = strtolower($host);
        
        if ($host !== '' && !$this->isValidDomain($host) && !$this->isValidIpv4($host) && !$this->isValidIpv6($host)) {
            throw new \InvalidArgumentException("Invalid hostname '$host'");
        }
        
        $this->host = $host;
    }
992792
private function _isReserved($host){
        if (!preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $host)) {
            $host = gethostbyname($host);
        }

        $octet = explode('.',$host);
        if ((int)$octet[0] >= 224) {
            return true;
        } else if (array_key_exists($octet[0], $this->_invalidIp)) {
            foreach ((array)$this->_invalidIp[$octet[0]] as $subnetData) {
                // we skip the first loop as we already know that octet matches
                for ($i = 1; $i < 4; $i++) {
                    if (strpos($subnetData, $octet[$i]) !== $i * 4) {
                        break;
                    }
                }

                $host       = explode("/", $subnetData);
                $binaryHost = "";
                $tmp        = explode(".", $host[0]);
                for ($i = 0; $i < 4 ; $i++) {
                    $binaryHost .= str_pad(decbin($tmp[$i]), 8, "0", STR_PAD_LEFT);
                }

                $segmentData = array(
                    'network'   => (int)$this->_toIp(str_pad(substr($binaryHost, 0, $host[1]), 32, 0)),
                    'broadcast' => (int)$this->_toIp(str_pad(substr($binaryHost, 0, $host[1]), 32, 1))
                );

                for ($j = $i; $j < 4; $j++) {
                    if ((int)$octet[$j] < $segmentData['network'][$j] ||
                        (int)$octet[$j] > $segmentData['broadcast'][$j]) {
                        return false;
                    }
                }
            }

            return true;
        } else {
            return false;
        }
    }
378889
public function host($host = '') {
        if ($host) {
            $this->host = $host;
        }
        if (!$this->host) {
            $this->host = self::server('HTTP_HOST');
        }
        return $this->host;
    }
179510
public function isValid($domain)
    {
        $this->setFormat('object');
        $Result = $this->parse($domain, '');

        return $Result->validHostname;
    }
77592
static function isSameHost($url)
    {
        $urlParts = parse_url($url);
        if(
            isset($_SERVER['SERVER_NAME']) &&
            $_SERVER['SERVER_NAME'] == $urlParts['host']
        ){
            return true;
        }

        return false;
    }
1259502
public function isSameHost(string $host, array $globalConstraints): bool
    {
        if ($this->host === null) {
            return true;
        }

        if (\mb_strpos($this->host, '{') === false) {
            return $this->host === $host;
        }

        $regex = $this->extractInlineContraints($this->host, 'hostConstraints');

        $regex = \preg_replace('/\{(\w+?)\}/', '(?P<$1>[^.]++)', $regex);

        $constraints = \array_merge($globalConstraints, $this->hostConstraints);
        foreach ($constraints as $id => $regexRule) {
            $regex = \str_replace('<' . $id . '>[^.]++', '<' . $id . '>' . $regexRule, $regex);
        }
        $pattern = '#^' . $regex . '$#s';
        $matches = [];

        if (\preg_match($pattern, $host, $matches)) {
            \array_shift($matches);
            $this->saveHostParameters($matches);

            return true;
        }

        return false;
    }
281189
public function validateIP($ipAddress = null)
    {
        if ($ipAddress === null) {
            $parsed = parse_url($this->uri);
            $ipAddress = isset($parsed['host']) ? $parsed['host'] : null;
        }
        return (
            filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ||
            filter_var(trim($ipAddress, '[]'), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)
        );
    }
892005
private function isReserved(string $host): bool
    {
        $hosts = [$host];
        if (!\preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $host)) {
            $tmp = \gethostbynamel($host);
            $hosts = $tmp !== false ? $tmp : [];
        }

        $res = true;
        $flags = FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE;
        foreach ($hosts as $host) {
            if (\filter_var($host, FILTER_VALIDATE_IP, ['flags' => $flags]) !== false) {
                $res = false;
                break;
            }
        }

        return $res;
    }
1069537
private function isValidIpv6Hostname(string $host): bool
    {
        [$ipv6, $scope] = explode('%', $host, 2) + [1 => null];
        if (null === $scope) {
            return (bool) filter_var($ipv6, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
        }

        $scope = rawurldecode('%'.$scope);

        return 1 !== preg_match(self::REGEXP_NON_ASCII_PATTERN, $scope)
            && 1 !== preg_match(self::REGEXP_GEN_DELIMS, $scope)
            && filter_var($ipv6, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)
            && 0 === strpos((string) inet_pton((string) $ipv6), self::ADDRESS_BLOCK);
    }
1096618
public static boolean verify(String host, String username, String password, int port) throws SMTPException {
	try {
	    return _verify(host, username, password, port);
	}
	catch (MessagingException e) {

	    // check user
	    if (!StringUtil.isEmpty(username)) {
		try {
		    _verify(host, null, null, port);
		    throw new SMTPExceptionImpl("can't connect to mail server, authentication settings are invalid");
		}
		catch (MessagingException e1) {

		}
	    }
	    // check port
	    if (port > 0 && port != 25) {
		try {
		    _verify(host, null, null, 25);
		    throw new SMTPExceptionImpl("can't connect to mail server, port definition is invalid");
		}
		catch (MessagingException e1) {}
	    }

	    throw new SMTPExceptionImpl("can't connect to mail server");
	}
    }
162582
public static function isValid($port)
    {
        $port_valid = false;

        if (is_int($port)) {
            $port_valid = self::portIsInValidRange($port);
        } elseif (is_null($port)) {
            $port_valid = true;
        }

        return $port_valid;
    }
687638
protected function filterHost($host)
    {
        if ($host) {
            if (filter_var($host, FILTER_VALIDATE_IP)) {
                $host = strval($host);
            } elseif (preg_match(
                '/^(?:[' . self::CHARACTERS_UNRESERVED . self::CHARACTERS_SUB_DELIMS . ':@\/\?]+|%[A-Fa-f0-9]{2})+$/',
                $host
            )
            ) {
                $host = strval($host);
            } else {
                throw new InvalidArgumentException('Invalid host "%s".', $host);
            }
        } else {
            $host = '';
        }

        return $host;
    }
1112372
private boolean validateServer(String host, int port){
        if(host==null || host.isEmpty()){
            return false;
        }
        if(port <=0 || port > 65535){
            return false;
        }
        return true;
    }
880921
public static function isPortOpen($host, $port, $protocol)
    {
        $protocol = strtolower($protocol);
        
        if ($protocol != 'tcp' && $protocol != 'udp')
        {
            $errMsg = 'Unrecognized protocol [' . $protocol . '] ' . 
                      'please specify [tcp] or [udp]';
            throw new \Exception($errMsg);
        }
        
        if (empty($host))
        {
            $host = self::getPublicIp();
        }

        foreach ($ports as $port)
        {
            $connection = @fsockopen($host, $port);

            if (is_resource($connection))
            {
                $isOpen = true;
                fclose($connection);
            }

            else
            {
                $isOpen = false;
            }
        }
        
        return $isOpen;
    }
758769
public function hostExists($url)
    {
        if (strpos($url, '/') === false) {
            $server = $url;
        } else {
            $server = @parse_url($url, PHP_URL_HOST);
        }
        if (!$server) {
            return false;
        }
        $ips = gethostbynamel($server);

        return !empty($ips);
    }
770891
public function validateHost($host = null)
    {
        if ($host === null) {
            $parsed = parse_url($this->uri);
            $host = isset($parsed['host']) ? $parsed['host'] : $parsed['path'];
        }
        return (
            preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $host) //valid chars check
            && preg_match("/^.{1,253}$/", $host) //overall length check
            && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $host) //length of each label
            && !$this->validateIP($host)
        );
    }