Skip to content

Instantly share code, notes, and snippets.

@0xspade
Last active October 1, 2019 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xspade/b4ad3ecbd924eefea8532c24e96acc87 to your computer and use it in GitHub Desktop.
Save 0xspade/b4ad3ecbd924eefea8532c24e96acc87 to your computer and use it in GitHub Desktop.
#!/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