Skip to content

Instantly share code, notes, and snippets.

@josephdunn
Last active October 10, 2016 20:50
Show Gist options
  • Save josephdunn/5557b7ead88a22624570bedb96639120 to your computer and use it in GitHub Desktop.
Save josephdunn/5557b7ead88a22624570bedb96639120 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# To use:
#
# 1. Run this script, it will generate pywhole.hosts
# 2. Get pywhole.hosts copied into /tmp on your DD-WRT router
# 3. Add the following line to your "Additional DNSMasq Options" in Services section of your DD-WRT admin interface:
#
# addn-hosts=/tmp/pywhole.hosts
#
# 4. Profit!
#
import re
import requests
hosts = []
with open('whitelist', 'r') as f:
whitelist = f.readlines()
whitelist = [ x.strip() for x in whitelist ]
for rowList in requests.get('https://github.com/pi-hole/pi-hole/raw/master/adlists.default').text.split('\n'):
if len(rowList) > 0 and rowList[0] != '#':
for rowEntry in requests.get(rowList).text.split('\n'):
if len(rowEntry) > 0 and rowEntry[0] != '#' and not rowEntry.startswith('127.0.0.1 local') and not rowEntry.startswith('255.') and not rowEntry.startswith('::1') and not rowEntry.startswith('fe80::'):
rowEntry = rowEntry.partition('#')[0] # remove comments
for entry in re.findall('(\d+\.\d+\.\d+\.\d+\s+)?(.+\..+)', rowEntry):
hosts.append(entry[1].lower().strip())
with open('pywhole.hosts', 'w') as f:
for host in set(sorted(hosts)):
if host not in whitelist:
f.write('0.0.0.0 ' + host + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment