Skip to content

Instantly share code, notes, and snippets.

@marcelloinfoweb
Created October 9, 2021 16:11
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 marcelloinfoweb/fcf417c3cf2c05d4dd426f54740f722d to your computer and use it in GitHub Desktop.
Save marcelloinfoweb/fcf417c3cf2c05d4dd426f54740f722d to your computer and use it in GitHub Desktop.
O script baixa as listas, ordena os links, deixa links únicos e salva no arquivo para o padrão do formato do Unbound.
#!/bin/sh
## Clean up any stale tempfile
echo "Removing old files..."
[ -f /tmp/hosts.working ] && rm -f /tmp/hosts.working
## Awk regex to be inverse-matched as whitelist
# - SolveMedia is needed for captchas on some websites
whitelist='/(api.solvemedia.com)/'
# All Blacklists
blacklist='https://raw.githubusercontent.com/neodevpro/neodevhost/master/lite_host http://winhelp2002.mvps.org/hosts.txt https://adaway.org/hosts.txt https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts https://www.stopforumspam.com/downloads/toxic_domains_whole.txt >
## Fetch all Blacklist Files
echo "Fetching Blacklists..."
for url in $blacklist; do
curl --silent $url >> "/tmp/hosts.working"
done
## Process Blacklist, Eliminiating Duplicates, Integrating Whitelist, and Converting to unbound format
echo "Processing Blacklist..."
awk -v whitelist="$whitelist" '$1 ~ /^127\.|^0\./ && $2 !~ whitelist {gsub("\r",""); print tolower($2)}' /tmp/hosts.working | sort | uniq | \
awk '{print "local-zone: \""$1"\" redirect\nlocal-data: \""$1" A 0.0.0.0\""}' > /etc/unbound/ad-blacklist
#awk '{printf "server:\n", $1; printf "local-data: \"%s A 0.0.0.0\"\n", $1}' > /etc/unbound/ad-blacklist
# Clean up tempfile
echo "Cleaning Up..."
rm -f '/tmp/hosts.working'
echo "Restarting Unbound ... "
systemctl restart unbound.service
echo "... Done restart!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment