Exemplo n.º 1
0
        public DnsQuestion(DnsString query, QueryType questionType, QueryClass questionClass)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            QueryName     = query;
            QuestionType  = questionType;
            QuestionClass = questionClass;
        }
Exemplo n.º 2
0
        // only used by the DnsQuestion as we don't expect any escaped chars in the actual query posted to and send back from the DNS Server (not supported).
        public DnsString ReadQuestionQueryString()
        {
            var result = new StringBuilder();

            foreach (var labelArray in ReadLabels())
            {
                var label = Encoding.UTF8.GetString(labelArray.Array, labelArray.Offset, labelArray.Count);
                result.Append(label);
                result.Append(".");
            }

            string value = result.ToString();

            return(DnsString.FromResponseQueryString(value));
        }
        private static IPHostEntry GetHostEntryProcessResult(DnsString hostString, DnsResourceRecord[] allRecords)
        {
            var addressRecords = allRecords
                                 .OfType <AddressRecord>()
                                 .Select(p => new
            {
                Address = p.Address,
                Alias   = DnsString.FromResponseQueryString(p.DomainName)
            })
                                 .ToArray();

            var hostEntry = new IPHostEntry()
            {
                Aliases     = new string[0],
                AddressList = addressRecords
                              .Select(p => p.Address)
                              .ToArray()
            };

            if (addressRecords.Length > 1)
            {
                if (addressRecords.Any(p => !p.Alias.Equals(hostString)))
                {
                    hostEntry.Aliases = addressRecords
                                        .Select(p => p.Alias.ToString())
                                        .Select(p => p.Substring(0, p.Length - 1))
                                        .Distinct()
                                        .ToArray();
                }
            }
            else if (addressRecords.Length == 1)
            {
                if (allRecords.Any(p => !DnsString.FromResponseQueryString(p.DomainName).Equals(hostString)))
                {
                    hostEntry.Aliases = allRecords
                                        .Select(p => p.DomainName.ToString())
                                        .Select(p => p.Substring(0, p.Length - 1))
                                        .Distinct()
                                        .ToArray();
                }
            }

            hostEntry.HostName = hostString.Value.Substring(0, hostString.Value.Length - 1);

            return(hostEntry);
        }
        private static IPHostEntry GetHostEntryFromName(IDnsQuery query, string hostName)
        {
            if (string.IsNullOrWhiteSpace(hostName))
            {
                throw new ArgumentNullException(nameof(hostName));
            }

            var hostString = DnsString.FromResponseQueryString(hostName);
            var ipv4Result = query.Query(hostString, QueryType.A);
            var ipv6Result = query.Query(hostString, QueryType.AAAA);

            var allRecords = ipv4Result
                             .Answers.Concat(ipv6Result.Answers)
                             .ToArray();

            return(GetHostEntryProcessResult(hostString, allRecords));
        }
        private static async Task <IPHostEntry> GetHostEntryFromNameAsync(IDnsQuery query, string hostName)
        {
            if (string.IsNullOrWhiteSpace(hostName))
            {
                throw new ArgumentNullException(nameof(hostName));
            }

            var hostString = DnsString.FromResponseQueryString(hostName);
            var ipv4Result = query.QueryAsync(hostString, QueryType.A);
            var ipv6Result = query.QueryAsync(hostString, QueryType.AAAA);

            await Task.WhenAll(ipv4Result, ipv6Result).ConfigureAwait(false);

            var allRecords = ipv4Result.Result
                             .Answers.Concat(ipv6Result.Result.Answers)
                             .ToArray();

            return(GetHostEntryProcessResult(hostString, allRecords));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DnsQuestion"/> class.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="questionType">Type of the question.</param>
 /// <param name="questionClass">The question class.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="query"/> is null.</exception>
 public DnsQuestion(DnsString query, PseudoResourceRecordType questionType, QueryClass questionClass)
 {
     QueryName     = query ?? throw new ArgumentNullException(nameof(query));
     QuestionType  = questionType;
     QuestionClass = questionClass;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DnsQuestion"/> class.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="questionType">Type of the question.</param>
 /// <param name="questionClass">The question class.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="query"/> is null.</exception>
 public DnsQuestion(string query, PseudoResourceRecordType questionType, QueryClass questionClass)
     : this(DnsString.Parse(query), questionType, questionClass)
 {
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DnsQuestion"/> class.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="questionType">Type of the question.</param>
 /// <param name="questionClass">The question class.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="query"/> is null.</exception>
 public DnsQuestion(DnsString query, QueryType questionType, QueryClass questionClass = QueryClass.IN)
 {
     QueryName     = query ?? throw new ArgumentNullException(nameof(query));
     QuestionType  = questionType;
     QuestionClass = questionClass;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DnsQuestion"/> class.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="questionType">Type of the question.</param>
 /// <param name="questionClass">The question class.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="query"/> is null.</exception>
 public DnsQuestion(string query, QueryType questionType, QueryClass questionClass = QueryClass.IN)
     : this(DnsString.Parse(query), questionType, questionClass)
 {
 }