Exemple #1
0
        public IHttpActionResult GetIPByHostname(string hostName, QueryType type)
        {
            var client = new LookupClient();
            IDnsQueryResponse result = null;
            RecordDto         record = new RecordDto()
            {
                HostName = new List <string>()
                {
                    hostName
                }, Type = type.ToString()
            };

            switch (type)
            {
            default:
            case QueryType.A:
                result           = _client.Query(hostName, QueryType.A);
                record.IPAddress = result.Answers.ARecords().FirstOrDefault().Address.ToString();
                break;

            case QueryType.AAAA:

                result           = _client.Query(hostName, QueryType.AAAA);
                record.IPAddress = result.Answers.AaaaRecords().FirstOrDefault().Address.ToString();
                break;
            }
            ;
            var linkedResource = new
            {
                value = record,
                links = CreateLinks(record)
            };

            return(Ok(linkedResource));
        }
        public async Task <bool> ValidateDomainAsync(string id)
        {
            var domainName = await domainRepository.ReadAsync(d => d.Id == id);

            if (domainName == null)
            {
                throw new NotFoundException();
            }

            var result = lookupClient.Query($"{domainName.Id}.{domainName.Value}", QueryType.TXT);

            if (result.Answers.OfType <TxtRecord>().Any(record => record.Text.Any(a => a == domainName.ValidationKey)))
            {
                domainName.ValidationDate = DateTime.UtcNow;

                return(await domainRepository.UpdateAsync(domainName) > 0);
            }

            return(false);
        }
Exemple #3
0
 private static IDnsQueryResponse Query(ILookupClient lookup, string host, QueryType t)
 {
     return(lookup.Query(host, t));
 }