Example #1
0
        /// <summary>
        /// Resolves the hostname and checks whether the opened port (if specified) is being opened on the remote host.
        /// </summary>
        /// <param name="servicesProvider"></param>
        /// <returns>IPStatus, if remote host has accepted connection, otherwise unknown. None IP address if host could not be resolved. True if port is being oepened.</returns>
        private async Task <Tuple <IPStatus, IPAddress, bool> > TryConnectAsync(ServerServicesProvider servicesProvider)
        {
            var ipAddress = servicesProvider.DnsResolver.GetIpAddress(_configuration.Hostname);

            if (Equals(ipAddress, IPAddress.None))
            {
                return(new Tuple <IPStatus, IPAddress, bool>(IPStatus.Unknown, IPAddress.None, false));
            }

            var portOpened = false;
            var ipStatus   = await servicesProvider.Pinger.PingAsync(ipAddress, _configuration.Timeout);

            if (_configuration.Port > 0)
            {
                await servicesProvider.TcpClient.ConnectAsync(ipAddress, _configuration.Port, _configuration.Timeout);

                portOpened = servicesProvider.TcpClient.IsConnected;
            }

            return(new Tuple <IPStatus, IPAddress, bool>(ipStatus, ipAddress, portOpened));
        }
Example #2
0
        /// <summary>
        /// Resolves the hostname and checks whether the opened port (if specified) is being opened on the remote host.
        /// </summary>
        /// <param name="servicesProvider"></param>
        /// <returns>IPStatus, if remote host has accepted connection, otherwise unknown. None IP address if host could not be resolved. True if port is being oepened.</returns>
        private async Task<Tuple<IPStatus, IPAddress, bool>> TryConnectAsync(ServerServicesProvider servicesProvider)
        {
            var ipAddress = servicesProvider.DnsResolver.GetIpAddress(_configuration.Hostname);
            if (Equals(ipAddress, IPAddress.None))
                return new Tuple<IPStatus, IPAddress, bool>(IPStatus.Unknown, IPAddress.None, false);

            var portOpened = false;
            var ipStatus = await servicesProvider.Pinger.PingAsync(ipAddress, _configuration.Timeout);
            if (_configuration.Port > 0)
            {
                await servicesProvider.TcpClient.ConnectAsync(ipAddress, _configuration.Port, _configuration.Timeout);
                portOpened = servicesProvider.TcpClient.IsConnected;
            }

            return new Tuple<IPStatus, IPAddress, bool>(ipStatus, ipAddress, portOpened);
        }