Skip to content

Instantly share code, notes, and snippets.

@skanjo
Forked from jac18281828/filter_unicode.py
Created June 21, 2017 16:21
Show Gist options
  • Save skanjo/0f1fb708e7f2067859f8751db0e1b95d to your computer and use it in GitHub Desktop.
Save skanjo/0f1fb708e7f2067859f8751db0e1b95d to your computer and use it in GitHub Desktop.
Ad Blocking script for dnsmasq. This uses Steven Black's Ad Blocking /etc/hosts file but converts it to dnsmasq format. This could be used with either the AdBlocking Raspberry PI project or on a Unify EdgeRouter
#!/bin/bash
ad_hosts_url="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
# The IP address below should point to the IP where blocked traffic should go
# or to a non routable address such as 0.0.0.0
# OpenDNS block page
# pixelserv_ip="146.112.61.104"
# not routable address
pixelserv_ip="0.0.0.0"
ad_file="/etc/dnsmasq.d/dnsmasq.adlist.conf"
temp_ad_file="/tmp/dnsmasq.adlist.conf.tmp"
curl -sk ${ad_hosts_url} | \
sed "/^\s*\#/d" - | \
sed "/^\s*\$/d" - > ${temp_ad_file}
if [ -f "$temp_ad_file" ]
then
# blacklist sites
cat << EOF >> ${temp_ad_file}
0.0.0.0 blacklist.site.com
EOF
# convert to dnsmasq
cat ${temp_ad_file} | \
sed '/whitelist\.gmail\.com/d' - | \
awk '$1 == "0.0.0.0" { print "address=/" $2 "/" $1 "/" }' - | \
sort | uniq > ${ad_file}
rm -f ${temp_ad_file}
else
echo "Error building the ad list, please try again."
exit
fi
/etc/init.d/dnsmasq force-reload
@airdogvan
Copy link

thanks a million that script was very useful for me!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment