Skip to content

Instantly share code, notes, and snippets.

@DamianZaremba
Created August 12, 2012 21:21
Show Gist options
  • Save DamianZaremba/3334541 to your computer and use it in GitHub Desktop.
Save DamianZaremba/3334541 to your computer and use it in GitHub Desktop.
Get the current cloudflare ip ranges
#!/usr/bin/python
import urllib2
from BeautifulSoup import BeautifulSoup
if __name__ == "__main__":
try:
response = urllib2.urlopen("https://www.cloudflare.com/wiki/index.php"\
"?title=What_are_the_CloudFlare_IP_address"\
"_ranges&action=render")
except urllib2.HTTPError, e:
print "Could not grab page, server returned %d" % e.code
except urllib2.URLError, e:
print "Could not reach the server to grab page: %s" % e.reason
else:
data = response.read()
soup = BeautifulSoup(data)
for range in soup.findAll('li'):
slash = range.string.split(' ')[0]
print slash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment