Generates a host list of first-party trackers for ad-blocking.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
769 B

#!/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:
if is_subdomain_matching(line):