예제 #1
0
        public async Task UpdateDnsResultsForRecordAsync(WatchedRecord record)
        {
            var query = !string.IsNullOrWhiteSpace(record.Prefix)
                                ? $"{record.Prefix}.{record.WatchedDomain.DomainName}"
                                : record.WatchedDomain.DomainName;

            var servers = await _dnsServersService.GetDnsServersAsync();

            foreach (var server in servers.DnsServers)
            {
                var data = new DnsQueryData
                {
                    Domain     = query,
                    RecordType = record.RecordType,
                    Ip         = server.IpAddress,
                    Port       = server.Port
                };
                var result = await _dnsResolver.ResolveDnsQuery(data);

                var existingResult = record.Results
                                     .FirstOrDefault(e => e.DnsServerId == server.Id);
                if (existingResult != null)
                {
                    existingResult.Value      = result.Value;
                    existingResult.TimeToLive = result.TimeToLive;
                }
                else
                {
                    var newResult = new RecordServerResult
                    {
                        Value       = result.Value,
                        TimeToLive  = result.TimeToLive,
                        DnsServerId = server.Id
                    };
                    record.Results.Add(newResult);
                }
            }

            await _context.SaveChangesAsync();
        }
예제 #2
0
 public Task <DnsServersDto> GetDnsServers()
 {
     return(_dnsServersService.GetDnsServersAsync());
 }