Skip to content

Instantly share code, notes, and snippets.

@drj11
Created May 23, 2016 08:58
Show Gist options
  • Save drj11/f0efd729365400d83f3e3717fd423654 to your computer and use it in GitHub Desktop.
Save drj11/f0efd729365400d83f3e3717fd423654 to your computer and use it in GitHub Desktop.
for current_attempt in range(MAX_DNS_ATTEMPTS):
print("Checking for DNS record, attempt: {}/{}".format(current_attempt+1, MAX_DNS_ATTEMPTS))
try:
dns_answer = dns.resolver.query(host, 'TXT')
if not dns_answer:
continue
for dns_rrset in dns_answer.rrset:
dns_text = dns_rrset.to_text()
# DNS library quotes returned strings - for comparisons we
# need to remove them
if dns_text.startswith('"') and dns_text.endswith('"'):
dns_text = dns_text[1:-1]
print("DNS response: " + dns_text)
print("Challenge: " + challenge)
if dns_text == challenge:
break
except dns.exception.Timeout:
print("DNS timeout, quitting...")
sys.exit(1)
except dns.resolver.NXDOMAIN:
pass
except dns.resolver.NoAnswer:
pass
time.sleep(LOOKUP_SLEEP_SECONDS)
current_attempt += 1
else:
print("Failed to find record for: " + domain)
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment