示例#1
0
        private async Task <bool> HasSoaRecordAsync(DomainName domainName)
        {
            // Check if there's an SOA record (start of authority)
            var response = await dns.QueryAsync(NameServer.Google, domainName.Name, DnsRecordType.SOA);

            return(response.Answers.Length > 0);
        }
示例#2
0
        private async Task <IReadOnlyList <DomainRecord> > SyncSet <T>(IDomain domain, DnsRecordType type)
        {
            var response = await dns.QueryAsync(NameServer.Google, domain.Name, type);

            var added = new List <DomainRecord>();

            foreach (var record in response.Answers)
            {
                if (record.Data is T recordData)
                {
                    var newRecord = await CreateAsync(
                        new CreateDomainRecordRequest(
                            domainId : domain.Id,
                            name     : "@",
                            type     : record.Type,
                            value    : recordData.ToString(),
                            ttl      : TimeSpan.FromSeconds(record.Ttl)
                            )
                        );

                    added.Add(newRecord);
                }
            }

            return(added);
        }
示例#3
0
        /// <summary>
        /// Query TXT records for specified domain names
        /// </summary>
        /// <param name="domain"></param>
        /// <returns></returns>
        public async Task <List <string> > QueryTxtRecord(string domain)
        {
            var dns = new DnsClient()
            {
                Servers = new[] { IPAddress.Parse("8.8.8.8"), IPAddress.Parse("114.114.114.114") }
            };

            try
            {
                var response = await dns.QueryAsync(domain, DnsType.TXT);

                var strings = response.Answers
                              .OfType <TXTRecord>()
                              .SelectMany(txt => txt.Strings);
                return(strings.ToList());
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Dns resolve error.");
            }
            return(new List <string>());
        }