Ejemplo n.º 1
0
        /// <summary>
        /// Produces a command socket to the FTP server
        /// </summary>
        /// <returns></returns>
        private async Task ConnectCommandSocketAsync()
        {
            try
            {
                Logger?.LogDebug($"Connecting command socket, {Configuration.Host}:{Configuration.Port}");

                var ipEndpoint = await dnsResolver.ResolveAsync(Configuration.Host, Configuration.Port, Configuration.IpVersion);

                commandSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                {
                    ReceiveTimeout = Configuration.TimeoutSeconds * 1000
                };
                commandSocket.Connect(ipEndpoint);

                var response = await GetResponseAsync();
                await BailIfResponseNotAsync(response, FtpStatusCode.SendUserCommand);
            }
            catch (Exception ex)
            {
                Logger?.LogDebug("Connecting to command socket failed");
                await LogOutAsync();

                throw new FtpException("Unable to login to FTP server", ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Queries a dns resolver for IP addresses of a host as an asynchronous operation.
        /// </summary>
        /// <param name="resolver"> The resolver instance, that should be used for queries </param>
        /// <param name="name"> Host name, that should be queried </param>
        /// <param name="token"> The token to monitor cancellation requests </param>
        /// <returns> A list of matching host addresses </returns>
        public static async Task <List <IPAddress> > ResolveHostAsync(this IDnsResolver resolver, DomainName name, CancellationToken token = default(CancellationToken))
        {
            List <IPAddress> result = new List <IPAddress>();

            List <AaaaRecord> aaaaRecords = await resolver.ResolveAsync <AaaaRecord>(name, RecordType.Aaaa, token : token);

            if (aaaaRecords != null)
            {
                result.AddRange(aaaaRecords.Select(x => x.Address));
            }

            List <ARecord> aRecords = await resolver.ResolveAsync <ARecord>(name, token : token);

            if (aRecords != null)
            {
                result.AddRange(aRecords.Select(x => x.Address));
            }

            return(result);
        }
        /// <summary>
        ///   Forces to update all hints using the given resolver
        /// </summary>
        /// <param name="resolver">The resolver to use for resolving the new hints</param>
#if NETSTANDARD
        public async System.Threading.Tasks.Task UpdateAsync(IDnsResolver resolver)
        {
            Zone zone = new Zone(DomainName.Root);

            var nameServer = await resolver.ResolveAsync <NsRecord>(DomainName.Root, RecordType.Ns);

            zone.AddRange(nameServer);

            var aRecordTasks     = new List <System.Threading.Tasks.Task <List <ARecord> > >(nameServer.Count);
            var aaaaRecordTasks  = new List <System.Threading.Tasks.Task <List <AaaaRecord> > >(nameServer.Count);
            var dnsKeyRecordTask = resolver.ResolveAsync <DnsKeyRecord>(DomainName.Root, RecordType.DnsKey);

            foreach (var nsRecord in nameServer)
            {
                aRecordTasks.Add(resolver.ResolveAsync <ARecord>(nsRecord.NameServer, RecordType.A));
                aaaaRecordTasks.Add(resolver.ResolveAsync <AaaaRecord>(nsRecord.NameServer, RecordType.Aaaa));
            }

            var aRecords = await System.Threading.Tasks.Task.WhenAll(aRecordTasks);

            foreach (var aRecordList in aRecords)
            {
                zone.AddRange(aRecordList);
            }

            var aaaaRecords = await System.Threading.Tasks.Task.WhenAll(aaaaRecordTasks);

            foreach (var aaaaRecordList in aaaaRecords)
            {
                zone.AddRange(aaaaRecordList);
            }

            zone.AddRange((await dnsKeyRecordTask).Where(x => x.IsSecureEntryPoint));

            LoadZoneInternal(zone);

            Save(zone);
        }
Ejemplo n.º 4
0
        protected async Task <Socket> ConnectSocketAsync(string host, int port, CancellationToken token)
        {
            try
            {
                Logger?.LogDebug("Connecting");
                var ipEndpoint = await dnsResolver.ResolveAsync(host, port, Configuration.IpVersion, token);

                var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                {
                    ReceiveTimeout = Configuration.TimeoutSeconds * 1000
                };
                socket.Connect(ipEndpoint);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                return(socket);
            }
            catch (Exception exception)
            {
                Logger?.LogError($"Could not to connect socket {host}:{port} - {exception.Message}", exception);
                throw;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 ///   Queries a dns resolver for specified records as an asynchronous operation.
 /// </summary>
 /// <typeparam name="T"> Type of records, that should be returned </typeparam>
 /// <param name="resolver"> The resolver instance, that should be used for queries </param>
 /// <param name="name"> Domain, that should be queried </param>
 /// <param name="recordType"> Type the should be queried </param>
 /// <param name="recordClass"> Class the should be queried </param>
 /// <param name="token"> The token to monitor cancellation requests </param>
 /// <returns> A list of matching <see cref="DnsRecordBase">records</see> </returns>
 public static Task <List <T> > ResolveAsync <T>(this IDnsResolver resolver, string name, RecordType recordType = RecordType.A, RecordClass recordClass = RecordClass.INet, CancellationToken token = default(CancellationToken))
     where T : DnsRecordBase
 {
     return(resolver.ResolveAsync <T>(DomainName.Parse(name), recordType, recordClass, token));
 }
Ejemplo n.º 6
0
        /// <summary>
        ///   Queries a dns resolver for reverse name of an IP address as an asynchronous operation.
        /// </summary>
        /// <param name="resolver"> The resolver instance, that should be used for queries </param>
        /// <param name="address"> The address, that should be queried </param>
        /// <param name="token"> The token to monitor cancellation requests </param>
        /// <returns> The reverse name of the IP address </returns>
        public static async Task <DomainName> ResolvePtrAsync(this IDnsResolver resolver, IPAddress address, CancellationToken token = default(CancellationToken))
        {
            List <PtrRecord> ptrRecords = await resolver.ResolveAsync <PtrRecord>(address.GetReverseLookupDomain(), RecordType.Ptr, token : token);

            return(ptrRecords.Select(x => x.PointerDomainName).FirstOrDefault());
        }