-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-find-rpz-ip.py
More file actions
72 lines (59 loc) · 2.63 KB
/
Copy pathtest-find-rpz-ip.py
File metadata and controls
72 lines (59 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import dns.resolver
import dns.query
import dns.zone
"""
This is a experimental scripts made for discover more method to check if the domain is blocked by RPZ, and the script
check if it include somethings in additional section and not a knew IP usually use by RPZ.
"""
def find_domains_with_additional_section(domains_file, dns_server, target_ip):
resolver = dns.resolver.Resolver()
resolver.nameservers = [dns_server]
output_file = "rpz-ip-find.txt"
with open(domains_file, "r") as f, open(output_file, "w") as out_f:
for domain in f:
domain = domain.strip()
try:
a_records = resolver.resolve(domain, "A")
domain_ips = [str(rdata) for rdata in a_records]
try:
response = dns.query.udp(
dns.message.make_query(domain, dns.rdatatype.A),
dns_server,
timeout=5,
)
if response.additional:
has_additional = True
additional_ips = []
for rrset in response.additional:
for rr in rrset:
if rr.rdtype == dns.rdatatype.A:
additional_ips.append(str(rr))
if (
not any(ip == target_ip for ip in additional_ips)
and target_ip not in domain_ips
):
out_f.write(f"{domain}\n")
print(
f"Found: {domain} - A records: {domain_ips}, Additional IPs: {additional_ips}"
)
else:
has_additional = False
except (dns.exception.Timeout, dns.exception.DNSException):
print(
f"Error querying additional section for {domain}: Timeout or other DNS error"
)
except dns.resolver.NXDOMAIN:
print(f"Domain not found: {domain}")
except dns.resolver.NoAnswer:
print(f"No A record found for: {domain}")
except dns.exception.DNSException as e:
print(f"Error resolving {domain}: {e}")
return output_file
if __name__ == "__main__":
domains_file = "domains.txt"
dns_server = "101.101.101.101"
target_ip = "182.173.0.181"
output_file_path = find_domains_with_additional_section(
domains_file, dns_server, target_ip
)
print(f"Results written to: {output_file_path}")