SHA256
Worked to tidy up ETPA.
This commit is contained in:
+30
-32
@@ -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] Additional section: {len(r.additional)} RRsets", file=sys.stderr)
|
||||||
print(f"[DEBUG] Full message: {r}", file=sys.stderr)
|
print(f"[DEBUG] Full message: {r}", file=sys.stderr)
|
||||||
|
|
||||||
# Check response code
|
results = []
|
||||||
response_rcode = r.rcode()
|
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
|
if response_rcode != 0: # 0 = NOERROR
|
||||||
rcode_name = rcode.to_text(response_rcode)
|
rcode_name = rcode.to_text(response_rcode)
|
||||||
return (full_domain, ns, f"RCODE: {rcode_name}")
|
return (full_domain, ns, f"RCODE: {rcode_name}")
|
||||||
|
|
||||||
results = []
|
# No records and NOERROR response
|
||||||
|
|
||||||
# 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
|
|
||||||
return (full_domain, ns, "NO RECORDS")
|
return (full_domain, ns, "NO RECORDS")
|
||||||
|
|
||||||
return (full_domain, ns, results)
|
|
||||||
except (exception.Timeout, TimeoutError):
|
except (exception.Timeout, TimeoutError):
|
||||||
return (full_domain, ns, "TIMED OUT")
|
return (full_domain, ns, "TIMED OUT")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user