Skip to content

Instantly share code, notes, and snippets.

@spagu
Created October 1, 2019 15:03
Show Gist options
  • Save spagu/e41dc73b35d6b5ccc2f8abb02c17fc1e to your computer and use it in GitHub Desktop.
Save spagu/e41dc73b35d6b5ccc2f8abb02c17fc1e to your computer and use it in GitHub Desktop.
Get and block IP address for DNSMASQ and PFCTL
#!/bin/sh
if [ ! -f /etc/hosts.blocked.org ]; then
cp /etc/hosts.blocked /etc/hosts.blocked.org
echo "no"
fi
TMP="/var/tmp/"
echo "" > ${TMP}output.txt
wget http://www.mvps.org/winhelp2002/hosts.zip -O ${TMP}1.zip
unzip ${TMP}1.zip -d ${TMP} HOSTS
cat ${TMP}HOSTS >>${TMP}output.txt
rm -f ${TMP}HOSTS
rm -f ${TMP}1.zip
rm -f ${TMP}readme.txt ${TMP}License.txt ${TMP}mvps.bat ${TMP}PrivacyPolicy.txt
wget http://hphosts.gt500.org/hosts.zip -O ${TMP}2.zip
unzip ${TMP}2.zip -d ${TMP} hosts.txt
cat ${TMP}hosts.txt >>${TMP}output.txt
rm -f ${TMP}hosts.txt
rm -f ${TMP}2.zip
rm -f ${TMP}readme.txt ${TMP}EULA.txt ${TMP}hosts.txt.sig
wget "http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=1&mimetype=plaintext" -O ${TMP}3.txt
cat ${TMP}3.txt >>${TMP}output.txt
rm -f ${TMP}3.txt
#wget http://www.everythingisnt.com/hoDsts -O ${TMP}4.txt
wget http://hosts-file.net/ad_servers.asp -O ${TMP}5.txt
cat ${TMP}5.txt >>${TMP}output.txt
rm -f ${TMP}5.txt
wget http://updates.it-mate.co.uk/updates.asp -O ${TMP}6.txt
cat ${TMP}6.txt >>${TMP}output.txt
rm -f ${TMP}6.txt
wget http://someonewhocares.org/hosts/hosts -O ${TMP}7.txt
cat ${TMP}7.txt >>${TMP}output.txt
rm -f ${TMP}7.txt
dosunix ${TMP}output.txt ${TMP}output1.txt
rm -f ${TMP}output.txt
mv ${TMP}output1.txt ${TMP}output.txt
cat ${TMP}output.txt | grep -v "^#" > ${TMP}output1.txt
#cp ${TMP}output1.txt ${TMP}full-1.txt
#cat ${TMP}output1.txt | grep -v "::" > ${TMP}output.txt
#cp ${TMP}output.txt ${TMP}full-1.txt
cat ${TMP}output1.txt | grep -v "^;" > ${TMP}output.txt
cp ${TMP}output.txt ${TMP}output1.txt
cat ${TMP}output1.txt | awk '{ print "127.0.0.1",$2 }' OFS="\t"> ${TMP}output.txt
#cp ${TMP}output.txt ${TMP}full1.txt
cat ${TMP}output1.txt | awk '{ print "::1",$2 }' OFS="\t">> ${TMP}output.txt
#cp ${TMP}output.txt ${TMP}full2.txt
cat ${TMP}output.txt | sort -n | uniq > ${TMP}output1.txt
rm -f ${TMP}output.txt
cat /etc/hosts.blocked.org > /etc/hosts.blockedlocal
cat ${TMP}output1.txt >> /etc/hosts.blockedlocal
rm -f ${TMP}output1.txt
cat /etc/hosts.blockedlocal > /etc/hosts.blocked
#sed 's/127.0.0.1/10.12.34.56/g' /etc/hosts.blockedlocal > /etc/hosts.blocked
#rm -f ${TMP}HOSTS
#rm -f ${TMP}hosts.txt
/usr/local/etc/rc.d/dnsmasq restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment