Browse Source

Error-proofed DNS-resolution

newworkflow_parseropti
Geoffrey Frogeye 3 years ago
parent
commit
0801bd9e44
  1. 15
      filter_subdomains.py

15
filter_subdomains.py

@ -10,10 +10,12 @@ import re
import sys
import dns.resolver
import dns.exception
import progressbar
import regexes
DNS_TIMEOUT = 5.0
def is_subdomain_matching(subdomain: str) -> bool:
"""
@ -21,9 +23,20 @@ def is_subdomain_matching(subdomain: str) -> bool:
"""
# TODO Look at the whole chain rather than the last one
try:
query = dns.resolver.query(subdomain, 'A')
query = dns.resolver.query(subdomain, 'A', lifetime=DNS_TIMEOUT)
except dns.resolver.NXDOMAIN:
return False
except dns.resolver.NoAnswer:
return False
except dns.resolver.YXDOMAIN:
print(f"Query name too long for {subdomain}", file=sys.stderr)
return False
except dns.resolver.NoNameservers:
print(f"All nameservers broken for {subdomain}", file=sys.stderr)
return False
except dns.exception.Timeout:
print(f"Timeout for {subdomain}", file=sys.stderr)
return False
canonical = query.canonical_name.to_text()
for regex in regexes.REGEXES:
if re.match(regex, canonical):

Loading…
Cancel
Save