Created
October 4, 2013 04:00
-
-
Save samrocketman/6820780 to your computer and use it in GitHub Desktop.
Generate a poisoned configuration file which bind can eat for blocking domain names. The file the script eats contains one domain per line.
This file contains hidden or 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 | |
#Created by Sam Gleske | |
#Thu Jun 7 20:43:09 EDT 2012 | |
adblockfile="dns_ad_block_list.txt" | |
adblocklistdir="/media/backup/Operating Systems - Linux/Fedora/16/configs" | |
adblocklist="${adblocklistdir}/${adblockfile}" | |
backup_dir="/media/backup/Operating Systems - Linux/Fedora/16/configs/etc/named" | |
outfile="/etc/named/named.conf.ads.block" | |
echo "Creating a unique domain list." | |
cp -f "$adblocklist" "${adblocklistdir}/${adblockfile%.txt}.bak.txt" || exit 1 | |
grep '^#' "$adblocklist" > "/tmp/$adblockfile" | |
sort -u "$adblocklist" | grep -v '#' >> "/tmp/$adblockfile" || exit 1 | |
mv "/tmp/$adblockfile" "$adblocklist" || exit 1 | |
chown sam:users "$adblocklist" "${adblocklistdir}/${adblockfile%.txt}.bak.txt" || exit 1 | |
chmod 644 "$adblocklist" "${adblocklistdir}/${adblockfile%.txt}.bak.txt" || exit 1 | |
echo "Converting ad block list to DNS zone file." | |
grep -v '#' "${adblocklist}" | awk '$0 != "" { print "zone \""$1"\" in { type master ; file \"poison\" ; };" }' > "$outfile" || exit 1 | |
echo "Back up new zone file." | |
cp -f "$outfile" "${backup_dir}/" || exit 1 | |
echo "Done." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment