Created
April 18, 2022 10:11
-
-
Save gabrieleromanato/f8e7b8834b117e6e89d3282f7af6a8c9 to your computer and use it in GitHub Desktop.
Cloudflare class to check whether a domain has been added to the service
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
from CloudflareRequest import CloudflareRequest | |
from CloudflareDNS import CloudflareDNS | |
class Cloudflare: | |
def __init__(self, host): | |
self.host = host | |
self.url = 'https://' + self.host | |
self.request = CloudflareRequest(self.url) | |
self.dns = CloudflareDNS(self.host) | |
def has_host_cloudflare_http_header(self, headers): | |
return 'Server' in headers and headers['Server'] == 'cloudflare' | |
def has_host_cloudflare_dns_records(self, response): | |
answer = response['Answer'] | |
has = True | |
for record in answer: | |
data = record['data'] | |
needle = 'ns.cloudflare.com' | |
if not needle in data: | |
has = False | |
return has | |
def check(self): | |
headers = self.request.send() | |
response = self.dns.resolve() | |
return self.has_host_cloudflare_http_header(headers) or self.has_host_cloudflare_dns_records(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment