More tidying.

This commit is contained in:
Discsearcher
2026-08-12 10:54:43 -04:00
parent 771af73845
commit 0335015fb9
+40 -1
View File
@@ -111,8 +111,37 @@ def perform_query(full_domain, ns, record_type, timeout):
if args.verbose: if args.verbose:
print(f"[DEBUG] UDP Response: Answer={len(r.answer)} RRsets, TC flag: {bool(r.flags & flags.TC)}", file=sys.stderr) print(f"[DEBUG] UDP Response: Answer={len(r.answer)} RRsets, TC flag: {bool(r.flags & flags.TC)}", file=sys.stderr)
# Check if UDP returned ETPA error - if so, try TCP
udp_rcode = r.rcode()
udp_rcode_name = rcode.to_text(udp_rcode)
if udp_rcode_name == "ETPA":
if args.verbose:
print(f"[DEBUG] UDP returned ETPA, retrying with TCP...", file=sys.stderr)
try:
r = query.tcp(q, ns, timeout=timeout)
protocol_used = "TCP"
if args.verbose:
print(f"[DEBUG] TCP Response: Answer={len(r.answer)} RRsets, TC flag: {bool(r.flags & flags.TC)}", file=sys.stderr)
# If TCP also returned ETPA, try TLS
tcp_rcode = r.rcode()
tcp_rcode_name = rcode.to_text(tcp_rcode)
if tcp_rcode_name == "ETPA":
if args.verbose:
print(f"[DEBUG] TCP also returned ETPA, retrying with TLS...", file=sys.stderr)
r = query.tls(q, ns, timeout=timeout)
protocol_used = "TLS"
if args.verbose:
print(f"[DEBUG] TLS Response: Answer={len(r.answer)} RRsets, TC flag: {bool(r.flags & flags.TC)}", file=sys.stderr)
except Exception as tcp_error:
# Fall back to TLS if TCP fails
if args.verbose:
print(f"[DEBUG] TCP failed ({tcp_error}), trying TLS...", file=sys.stderr)
r = query.tls(q, ns, timeout=timeout)
protocol_used = "TLS"
if args.verbose:
print(f"[DEBUG] TLS Response: Answer={len(r.answer)} RRsets, TC flag: {bool(r.flags & flags.TC)}", file=sys.stderr)
# If UDP returns truncated, retry with TCP # If UDP returns truncated, retry with TCP
if r.flags & flags.TC: elif r.flags & flags.TC:
if args.verbose: if args.verbose:
print(f"[DEBUG] UDP Response truncated (TC flag set), retrying with TCP...", file=sys.stderr) print(f"[DEBUG] UDP Response truncated (TC flag set), retrying with TCP...", file=sys.stderr)
try: try:
@@ -137,6 +166,16 @@ def perform_query(full_domain, ns, record_type, timeout):
protocol_used = "TCP" protocol_used = "TCP"
if args.verbose: if args.verbose:
print(f"[DEBUG] TCP Response: Answer={len(r.answer)} RRsets, TC flag: {bool(r.flags & flags.TC)}", file=sys.stderr) print(f"[DEBUG] TCP Response: Answer={len(r.answer)} RRsets, TC flag: {bool(r.flags & flags.TC)}", file=sys.stderr)
# If TCP returned ETPA, try TLS
tcp_rcode = r.rcode()
tcp_rcode_name = rcode.to_text(tcp_rcode)
if tcp_rcode_name == "ETPA":
if args.verbose:
print(f"[DEBUG] TCP returned ETPA, retrying with TLS...", file=sys.stderr)
r = query.tls(q, ns, timeout=timeout)
protocol_used = "TLS"
if args.verbose:
print(f"[DEBUG] TLS Response: Answer={len(r.answer)} RRsets, TC flag: {bool(r.flags & flags.TC)}", file=sys.stderr)
except Exception as tcp_error: except Exception as tcp_error:
# Fall back to TLS if TCP fails # Fall back to TLS if TCP fails
if args.verbose: if args.verbose: