29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
import socket
|
|
import struct
|
|
|
|
def test_ad_block(server_ip, domain="pagead2.googlesyndication.com"):
|
|
header = struct.pack(">HHHHHH", 0x1234, 0x0100, 1, 0, 0, 0)
|
|
qname = b"".join(bytes([len(p)]) + p.encode("ascii") for p in domain.split(".")) + b"\x00"
|
|
qtype_qclass = struct.pack(">HH", 1, 1)
|
|
packet = header + qname + qtype_qclass
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
sock.settimeout(3.0)
|
|
try:
|
|
sock.sendto(packet, (server_ip, 53))
|
|
resp, _ = sock.recvfrom(1024)
|
|
# Parse answer IP (last 4 bytes of standard A record answer)
|
|
if len(resp) >= 32:
|
|
ip = ".".join(str(b) for b in resp[-4:])
|
|
print(f"Server {server_ip} returned for {domain} -> {ip}")
|
|
if ip in ["0.0.0.0", "127.0.0.1"]:
|
|
print(f" [VERIFIED] Ad domain {domain} was BLOCKED (0.0.0.0)!")
|
|
except Exception as e:
|
|
print(f"Error querying {server_ip}: {e}")
|
|
finally:
|
|
sock.close()
|
|
|
|
test_ad_block("140.44.4.36")
|
|
test_ad_block("140.44.4.65")
|
|
|