import socket import sys sys.stdout.reconfigure(encoding='utf-8') # Simple DNS query packet generator def make_query(name, qtype=1): # 1=A, 12=PTR import random txid = random.randint(1, 65535) flags = 0x0100 # standard query, recursion desired qdcount = 1 header = txid.to_bytes(2, 'big') + flags.to_bytes(2, 'big') + qdcount.to_bytes(2, 'big') + b'\x00\x00\x00\x00\x00\x00' qname = b''.join([bytes([len(p)]) + p.encode('ascii') for p in name.split('.')]) + b'\x00' question = qname + qtype.to_bytes(2, 'big') + (1).to_bytes(2, 'big') # class IN return header + question, txid def query_server(server, name, qtype=1, port=53): packet, txid = make_query(name, qtype) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.settimeout(3.0) try: s.sendto(packet, (server, port)) data, _ = s.recvfrom(1024) # Parse basic response ancount = int.from_bytes(data[6:8], 'big') return True, ancount except Exception as e: return False, str(e) finally: s.close() targets = [ ("Aerodrome DNS VIP (140.44.4.36)", "140.44.4.36"), ("Spaceport DNS VIP (140.44.4.65)", "140.44.4.65"), ] queries = [ ("sninfr2lnxctl01.snarfnet.net", 1), ("sn-nas.snarfnet.net", 1), ("gateway.snarfnet.net", 1), ("app-test.snarfnet.net", 1), # Wildcard ("11.4.44.140.in-addr.arpa", 12), # Reverse PTR ("google.com", 1), # Upstream DoH recursion ] print("=======================================================") print(" TESTING DNS VIPS PORT 53 RESOLUTION ") print("=======================================================") for s_label, server in targets: print(f"\n--- Testing {s_label} ---") for q_name, qtype in queries: ok, res = query_server(server, q_name, qtype) if ok and res > 0: print(f" ✓ {q_name:<30} -> Resolved ({res} answers)") elif ok and res == 0: print(f" ? {q_name:<30} -> 0 answers returned") else: print(f" ✗ {q_name:<30} -> Error: {res}") print("\n=======================================================")