From c873680830e2f19c5b9a9ae0db41c1e829cd608cf8dfd97a14f905e607f67a9a Mon Sep 17 00:00:00 2001 From: Discsearcher Date: Wed, 12 Aug 2026 09:12:54 -0400 Subject: [PATCH] Worked to tidy up ETPA. --- dns_compare.py | 62 ++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/dns_compare.py b/dns_compare.py index 3f3082e..6cbd751 100755 --- a/dns_compare.py +++ b/dns_compare.py @@ -130,44 +130,42 @@ def perform_query(full_domain, ns, record_type, timeout): print(f"[DEBUG] Additional section: {len(r.additional)} RRsets", file=sys.stderr) print(f"[DEBUG] Full message: {r}", file=sys.stderr) - # Check response code + results = [] response_rcode = r.rcode() + + # Helper function to extract records of the requested type from a section + def extract_records_of_type(section, requested_type): + section_results = [] + if section: + for rrset in section: + # Only include RRsets that match the requested record type + if rrset.rdtype == requested_type: + for item in rrset: + section_results.append(str(item)) + return section_results + + # Check answer section first + results = extract_records_of_type(r.answer, record_type) + if results: + return (full_domain, ns, results) + + # If no answer, check additional section (some servers put records there) + results = extract_records_of_type(r.additional, record_type) + if results: + return (full_domain, ns, results) + + # If still no results, check authority section (only for SOA, NS, etc.) + results = extract_records_of_type(r.authority, record_type) + if results: + return (full_domain, ns, results) + + # Truly no records found - check if there's a non-NOERROR response code to report if response_rcode != 0: # 0 = NOERROR rcode_name = rcode.to_text(response_rcode) return (full_domain, ns, f"RCODE: {rcode_name}") - results = [] - - # Check answer section first - answers = r.answer - if answers: - for rrset in answers: - for item in rrset: - results.append(str(item)) - return (full_domain, ns, results) - - # If no answer, check additional section (some servers put records there) - additional = r.additional - if additional: - for rrset in additional: - for item in rrset: - results.append(str(item)) - if results: - return (full_domain, ns, results) - - # If still no results, check authority section - authority = r.authority - if authority: - for rrset in authority: - for item in rrset: - results.append(str(item)) - if results: - return (full_domain, ns, results) - - # Truly no records found + # No records and NOERROR response return (full_domain, ns, "NO RECORDS") - - return (full_domain, ns, results) except (exception.Timeout, TimeoutError): return (full_domain, ns, "TIMED OUT") except Exception as e: