Last active
October 1, 2019 02:22
-
-
Save 0xspade/b4ad3ecbd924eefea8532c24e96acc87 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python3 | |
import ipaddr, socket, cfscrape | |
site = 'site.com' | |
class grepcidr(): | |
def __init__(self, networks=None): | |
self.ipset = set() | |
if networks: | |
self.add(networks) | |
def add(self, networks): | |
for prefix in networks: | |
self.ipset.add(ipaddr.IPNetwork(prefix)) | |
def __contains__(self, other): | |
host = ipaddr.IPAddress(other) | |
for net in self.ipset: | |
if host in net: | |
return True | |
return False | |
cloudflare = [ | |
'173.245.48.0/20', | |
'103.21.244.0/22', | |
'103.22.200.0/22', | |
'103.31.4.0/22', | |
'141.101.64.0/18', | |
'108.162.192.0/18', | |
'190.93.240.0/20', | |
'188.114.96.0/20', | |
'197.234.240.0/22', | |
'198.41.128.0/17', | |
'162.158.0.0/15', | |
'104.16.0.0/12', | |
'172.64.0.0/13', | |
'131.0.72.0/22' | |
] | |
def cf(url): | |
scraper = cfscrape.create_scraper() | |
test = scraper.get(url) | |
return test.content | |
def string(text): | |
return str(b'%s', encoding='utf-8', errors='strict') %format(text) | |
if __name__=='__main__': | |
range = grepcidr(cloudflare) | |
ip = socket.gethostbyname(site) | |
if (ip in range) is True: | |
print("Site is cloudflare") | |
test = cf("https://"+site) | |
print(string(test)) | |
elif (ip in range) is False: | |
print("Site is not cloudflare") | |
wow = requests.get("https://"+site) | |
print(string(wow.content)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment