Created
December 12, 2017 15:32
-
-
Save fengb/3bcf71f48ee51aa2a1442cfa3355b2a7 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
target_ip=255.255.255.255 | |
whitelist=( | |
localhost.localdomain | |
local | |
localhost | |
broadcasthost | |
0.0.0.0 | |
) | |
# Ripped this list from Pi-Hole: | |
# https://raw.githubusercontent.com/pi-hole/pi-hole/master/adlists.default | |
hostfiles=( | |
https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts | |
https://mirror1.malwaredomains.com/files/justdomains | |
http://sysctl.org/cameleon/hosts | |
https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist | |
https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt | |
https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt | |
https://hosts-file.net/ad_servers.txt | |
) | |
regex_ip='[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | |
regex_whitelist="^($(sed -e 's#\.#\\.#g' -e 's# #|#g' <<<"${whitelist[@]}"))$" | |
function to_hosts { | |
sed -e "s/^/$target_ip /" | |
} | |
function to_dnsmasq { | |
sed -E "N;s#\\n#/#g;s#.*#address=/&/$target_ip#" | |
} | |
curl "${hostfiles[@]}" | \ | |
sed -E -e "s/^($regex_ip)?[[:space:]]+//g" -e 's/[[:space:]]*(#.*)?$//g' | \ | |
grep -E -v -e "$regex_whitelist" -e "[ #]" -e "^$" | \ | |
sort -u | \ | |
to_dnsmasq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment