Skip to content

Instantly share code, notes, and snippets.

@enginefeeder101
Last active June 16, 2018 00:23
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 enginefeeder101/67265845408df73ae2e36a9766160bf7 to your computer and use it in GitHub Desktop.
Save enginefeeder101/67265845408df73ae2e36a9766160bf7 to your computer and use it in GitHub Desktop.
Create Mega Adblock Hostsfile for use with Dnsmasq (Modified from Pi-hole)
#!/bin/bash
# Modified Pi-hole script to generate a generic hosts file
# for use with dnsmasq's addn-hosts configuration
# original : https://github.com/jacobsalmela/pi-hole/blob/master/gravity-adv.sh
# forked from: https://gist.github.com/chrisvella/5f3a18f1e442153cd685
### Configuration ###
# Server to send ads to
adblock='0.0.0.0'
# Blocklist location
outlist='/config/adblocklist'
tmplist=$(mktemp)
# Whitelist location
whitelist='/config/whitelist'
### Download domains ###
# StevenBlack
curl -s https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts | grep '^0.0.0.0' | awk '{print $2}' >> $tmplist
# MalwareDomains
curl -s https://mirror1.malwaredomains.com/files/justdomains >> $tmplist
# Cameleon
curl -s http://sysctl.org/cameleon/hosts | grep '^127.0.0.1' | awk '{print $2}' >> $tmplist
# Zeustracker
curl -s https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist >> $tmplist
# Disconnect.me
curl -s https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt >> $tmplist
curl -s https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt >> $tmplist
# Hosts-file.net
curl -s https://hosts-file.net/ad_servers.txt | grep '^127.0.0.1' | awk '{print $2}' >> $tmplist
curl -s https://hosts-file.net/emd.txt | grep '^127.0.0.1' | awk '{print $2}' >> $tmplist
curl -s https://hosts-file.net/fsa.txt | grep '^127.0.0.1' | awk '{print $2}' >> $tmplist
curl -s https://hosts-file.net/hjk.txt | grep '^127.0.0.1' | awk '{print $2}' >> $tmplist
curl -s https://hosts-file.net/mmt.txt | grep '^127.0.0.1' | awk '{print $2}' >> $tmplist
curl -s https://hosts-file.net/psh.txt | grep '^127.0.0.1' | awk '{print $2}' >> $tmplist
# YoYo
curl -s http://pgl.yoyo.org/adservers/serverlist.php?hostformat=nohtml >> $tmplist
# WinHelp2002
curl -s http://winhelp2002.mvps.org/hosts.txt | grep '^0.0.0.0' | awk '{print $2}' >> $tmplist
# AdAway
curl -s https://adaway.org/hosts.txt | grep '^127.0.0.1' | awk '{print $2}' >> $tmplist
# Malware Domain List
curl -s http://www.malwaredomainlist.com/hostslist/hosts.txt | grep '^127.0.0.1' | awk '{print $2}' >> $tmplist
# Some One Who Cares
curl -s http://someonewhocares.org/hosts/zero/hosts | grep '^0.0.0.0' | awk '{print $2}' >> $tmplist
# Mother of All Ad Blocks
curl -s -A 'Mozilla' http://adblock.mahakala.is | grep '^0.0.0.0' | awk '{print $2}' >> $tmplist
### Finalize and cleanup ###
# Combine blocklist and whitelist
comm -23 <(grep -v '#' $tmplist | tr -d '[:blank:]\r' | sort -u) <(grep -v '#' "$whitelist" | tr -d '[:blank:]\r' | sort -u) | awk -v "IP=$adblock" '{print IP" "$0}' > "$outlist"
# Removes temporary list
rm $tmplist
0.0.0.0
127.0.0.1
localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment