36 lines
769 B
Python
36 lines
769 B
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
"""
|
||
|
From a list of subdomains, output only
|
||
|
the ones resolving to a first-party tracker.
|
||
|
"""
|
||
|
|
||
|
import re
|
||
|
import sys
|
||
|
|
||
|
import dns.resolver
|
||
|
|
||
|
import regexes
|
||
|
|
||
|
|
||
|
def is_subdomain_matching(subdomain: str) -> bool:
|
||
|
"""
|
||
|
Indicates if the subdomain redirects to a first-party tracker.
|
||
|
"""
|
||
|
# TODO Look at the whole chain rather than the last one
|
||
|
query = dns.resolver.query(subdomain, 'A')
|
||
|
canonical = query.canonical_name.to_text()
|
||
|
for regex in regexes.REGEXES:
|
||
|
if re.match(regex, canonical):
|
||
|
return True
|
||
|
return False
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
for line in sys.stdin:
|
||
|
line = line.strip()
|
||
|
if not line:
|
||
|
continue
|
||
|
if is_subdomain_matching(line):
|
||
|
print(line)
|