public List<LookupRequest> Duplicates; // if any DNS lookup requests arrive with the same query they will be stored with the queued query. public LookupRequest(string hostname, DNSQType queryType, int timeout, List<IPEndPoint> dnsServers, ManualResetEvent completeEvent) { Hostname = hostname; QueryType = queryType; Timeout = timeout; DNSServers = dnsServers; CompleteEvent = completeEvent; }
/// <summary> /// Do an QClass=IN Query on specified DNS servers /// </summary> /// <param name="name">Name to query</param> /// <param name="qtype">Question type</param> /// <param name="timeout">Timeout for lookup in seconds.</param> /// <returns>Response of the query</returns> public DNSResponse Query(string name, DNSQType qtype, int timeout) { Question question = new Question(name, qtype, QClass.IN); DNSResponse response = SearchInCache(question); if (response != null) { return(response); } DNSRequest request = new DNSRequest(); request.AddQuestion(question); return(GetResponse(request, m_DnsServers, timeout)); }
public DNSResponse Query(string name, DNSQType qtype, int timeout, List<IPEndPoint> dnsServers) { Question question = new Question(name, qtype, QClass.IN); DNSResponse response = SearchInCache(question); if (response != null) return response; DNSRequest request = new DNSRequest(); request.AddQuestion(question); return GetResponse(request, dnsServers, timeout); }
/// <summary> /// Do Query on specified DNS servers /// </summary> /// <param name="name">Name to query</param> /// <param name="qtype">Question type</param> /// <param name="timeout">Timeout for lookup in seconds.</param> /// <param name="qclass">Class type</param> /// <returns>Response of the query</returns> public DNSResponse Query(string name, DNSQType qtype, QClass qclass, int timeout) { Question question = new Question(name, qtype, qclass); DNSResponse response = SearchInCache(question); if (response != null) return response; DNSRequest request = new DNSRequest(); request.AddQuestion(question); return GetResponse(request, m_DnsServers, timeout); }
/// <summary> /// Do an QClass=IN Query on the previously cached results. /// </summary> /// <param name="name">Name to query</param> /// <param name="qtype">Question type</param> /// <returns>Response of the query</returns> public DNSResponse QueryCache(string name, DNSQType qtype, QClass qclass) { Question question = new Question(name, qtype, qclass); return SearchInCache(question); }
/// <summary> /// Do an QClass=IN Query on the previously cached results. /// </summary> /// <param name="name">Name to query</param> /// <param name="qtype">Question type</param> /// <returns>Response of the query</returns> public DNSResponse QueryCache(string name, DNSQType qtype, QClass qclass) { Question question = new Question(name, qtype, qclass); return(SearchInCache(question)); }
public static DNSResponse LookupAsync(string hostname, DNSQType queryType) { int lookupTimeout = (queryType == DNSQType.A || queryType == DNSQType.AAAA) ? DEFAULT_A_RECORD_DNS_TIMEOUT : DEFAULT_DNS_TIMEOUT; return Lookup(hostname, queryType, lookupTimeout, null, true, true); }
public Question(string QName, DNSQType QType, QClass QClass) { this.QName = QName; this.QType = QType; this.QClass = QClass; }
/// <summary> /// This method will wait until either the lookup completes or the timeout is reached before returning. /// </summary> /// <param name="hostname">The hostname of the A record to lookup in DNS.</param> /// <param name="timeout">Timeout in seconds for the lookup.</param> /// <returns></returns> public static DNSResponse Lookup(string hostname, DNSQType queryType, int timeout, List<IPEndPoint> dnsServers) { return Lookup(hostname, queryType, timeout, dnsServers, true, false); }
public static DNSResponse Lookup(string hostname, DNSQType queryType, int timeout, List <IPEndPoint> dnsServers, bool useCache, bool async) { if (hostname == null || hostname.Trim().Length == 0) { return(null); } DNSResponse ipAddressResult = MatchIPAddress(hostname); if (ipAddressResult != null) { return(ipAddressResult); } else if (useCache) { DNSResponse cacheResult = m_resolver.QueryCache(hostname.Trim().ToLower(), queryType); if (cacheResult != null) { return(cacheResult); } } if (async) { //logger.Debug("DNS lookup cache miss for async lookup to " + queryType.ToString() + " " + hostname + "."); QueueLookup(new LookupRequest(hostname.Trim().ToLower(), queryType, timeout, dnsServers, null)); return(null); } else { ManualResetEvent completeEvent = new ManualResetEvent(false); QueueLookup(new LookupRequest(hostname.Trim().ToLower(), queryType, timeout, dnsServers, completeEvent)); if (completeEvent.WaitOne(timeout * 1000 * 2, false)) { //logger.Debug("Complete event fired for DNS lookup on " + queryType.ToString() + " " + hostname + "."); // Completed event was fired, the DNS entry will now be in cache. DNSResponse result = m_resolver.QueryCache(hostname, queryType); if (result != null) { return(result); } else { //logger.Debug("DNS lookup cache miss for " + queryType.ToString() + " " + hostname + "."); // Timeout. DNSResponse timeoutResponse = new DNSResponse(); timeoutResponse.Timedout = true; return(timeoutResponse); } } else { // If this block gets called it's because the DNS resolver class did not return within twice the timeout period it // was asked to do so in. If this happens a lot further investigation into the DNS resolver class is warranted. logger.Error("DNSManager timed out waiting for the DNS resolver to complete the lookup for " + queryType.ToString() + " " + hostname + "."); // Timeout. DNSResponse timeoutResponse = new DNSResponse(); timeoutResponse.Timedout = true; return(timeoutResponse); } } }
/// <summary> /// This method will wait until either the lookup completes or the timeout is reached before returning. /// </summary> /// <param name="hostname">The hostname of the A record to lookup in DNS.</param> /// <param name="timeout">Timeout in seconds for the lookup.</param> /// <returns></returns> public static DNSResponse Lookup(string hostname, DNSQType queryType, int timeout, List <IPEndPoint> dnsServers) { return(Lookup(hostname, queryType, timeout, dnsServers, true, false)); }
public static DNSResponse LookupAsync(string hostname, DNSQType queryType) { int lookupTimeout = (queryType == DNSQType.A || queryType == DNSQType.AAAA) ? DEFAULT_A_RECORD_DNS_TIMEOUT : DEFAULT_DNS_TIMEOUT; return(Lookup(hostname, queryType, lookupTimeout, null, true, true)); }
public Question(RecordReader rr) { QName = rr.ReadDomainName(); QType = (DNSQType)rr.ReadShort(); QClass = (QClass)rr.ReadShort(); }
public Question(string QName, DNSQType QType, QClass QClass) { this.QName = QName; this.QType = QType; this.QClass = QClass; }
public static DNSResponse Lookup(string hostname, DNSQType queryType, int timeout, List<IPEndPoint> dnsServers, bool useCache, bool async) { if (hostname == null || hostname.Trim().Length == 0) { return null; } DNSResponse ipAddressResult = MatchIPAddress(hostname); if (ipAddressResult != null) { return ipAddressResult; } else if (useCache) { DNSResponse cacheResult = m_resolver.QueryCache(hostname.Trim().ToLower(), queryType); if (cacheResult != null) { return cacheResult; } } if (async) { //logger.Debug("DNS lookup cache miss for async lookup to " + queryType.ToString() + " " + hostname + "."); QueueLookup(new LookupRequest(hostname.Trim().ToLower(), queryType, timeout, dnsServers, null)); return null; } else { ManualResetEvent completeEvent = new ManualResetEvent(false); QueueLookup(new LookupRequest(hostname.Trim().ToLower(), queryType, timeout, dnsServers, completeEvent)); if (completeEvent.WaitOne(timeout * 1000 * 2, false)) { //logger.Debug("Complete event fired for DNS lookup on " + queryType.ToString() + " " + hostname + "."); // Completed event was fired, the DNS entry will now be in cache. DNSResponse result = m_resolver.QueryCache(hostname, queryType); if (result != null) { return result; } else { //logger.Debug("DNS lookup cache miss for " + queryType.ToString() + " " + hostname + "."); // Timeout. DNSResponse timeoutResponse = new DNSResponse(); timeoutResponse.Timedout = true; return timeoutResponse; } } else { // If this block gets called it's because the DNS resolver class did not return within twice the timeout period it // was asked to do so in. If this happens a lot further investigation into the DNS resolver class is warranted. logger.Error("DNSManager timed out waiting for the DNS resolver to complete the lookup for " + queryType.ToString() + " " + hostname + "."); // Timeout. DNSResponse timeoutResponse = new DNSResponse(); timeoutResponse.Timedout = true; return timeoutResponse; } } }
public Question(RecordReader rr) { QName = rr.ReadDomainName(); QType = (DNSQType)rr.ReadShort(); QClass = (QClass)rr.ReadShort(); }
private void VerboseDNSLookup(string host, DNSQType queryType) { AppendTraceMessage("Looking up " + host + " query type " + queryType.ToString() + ".\n"); try { //DNSResponse dnsResponse = DNSManager.Lookup(host, queryType, 5, new List<IPEndPoint>{new IPEndPoint(IPAddress.Parse("128.59.16.20"), 53)}, false, false); DNSResponse dnsResponse = DNSManager.Lookup(host, queryType, 5, null, false, false); if (dnsResponse.Error == null) { List<AnswerRR> records = dnsResponse.Answers; //if (records.Count > 0) if (dnsResponse.RecordNAPTR.Length > 0) { AppendTraceMessage("Results for " + host + " query type " + queryType.ToString() + ".\n"); //foreach (AnswerRR record in records) foreach (RecordNAPTR record in dnsResponse.RecordNAPTR) { AppendTraceMessage(record.ToString() + "\n"); } } else { AppendTraceMessage("Empty result returned for " + host + " query type " + queryType.ToString() + ".\n"); } } else { AppendTraceMessage("DNS lookup error for " + host + " query type " + queryType.ToString() + ", " + dnsResponse.Error + ".\n"); } } catch (ApplicationException appExcp) { AppendTraceMessage(appExcp.Message); } }