Created
April 18, 2022 10:09
-
-
Save gabrieleromanato/b2b8097c031a968d37cd05c92d54a072 to your computer and use it in GitHub Desktop.
Cloudflare: get the NS records of a given domain via the Google DNS API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import validators | |
from validators import ValidationFailure | |
class CloudflareDNS: | |
def __init__(self, host): | |
self.host = host | |
self.record = 'NS' | |
self.api_url = 'https://dns.google/resolve?' | |
def resolve(self): | |
valid_domain = validators.domain(self.host.strip()) | |
if isinstance(valid_domain, ValidationFailure): | |
return False | |
url = self.api_url + 'name=' + self.host + '&type=' + self.record | |
r = requests.get(url, allow_redirects=True) | |
return r.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment