Fandom

InfoDepot Wiki

AD-Blocking with DD-WRT

1,124pages on
this wiki
Add New Page
Talk0 Share

ad-blocking with DD-WRT revisited (simple)

frater:Posted: Mon Feb 16, 2009 1:39 pm

I've been asked to start a new thread to get this add-blocking to work.

I will make 2 seperate threads. One thread is a simple one. It will resolve all those nasty domains to an IP of your choice. In my example I will use 0.0.0.0 but you can also change that to an ip on which you have pixelserv running.

First enable local dns and add the line

addn-hosts=/tmp/dlhosts

And put this in startup code.

_rogue=0.0.0.0
echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"$_rogue\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

or this one (which gives the possibility to add some custom hosts in either /opt/etc/hosts or /jffs/hosts):

_rogue=0.0.0.0
echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"$_rogue\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\n[ -e /jffs/hosts ] && cat /jffs/hosts >>/tmp/dlhosts\n[ -e /opt/etc/hosts ] && cat /opt/etc/hosts >>/tmp/dlhosts\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &


I will later make another thread where I'll be using the onboard webserver to answer the webcalls.

Sshot 61 203


frater:Posted: Mon Jun 08, 2009 7:02 am

With this script you can exclude some hosts and include others...

This is the script on MY router. I have an USB-stick, so I prefer to have my "dlhosts" on there....

If you have only jffs as permanent storage, you should change

_f=/opt/dlhosts

into

_f=/tmp/dlhosts


In /opt/etc/ I have a file called "hosts" its contents will be blindly added. In /opt/etc I als have a file called "dlhosts.exclude" in which I have the domains which should be stripped.

If you want to place them in /jffs you should change:

stor=/opt/etc

into

stor=/jffs


_rogue=192.168.10.5
wr=/tmp/write_dlhosts
echo -e "#!/bin/sh\nstor=/opt/etc\nxcl=\$stor/dlhosts.exclude\n_f=/opt/dlhosts\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"$_rogue\\\t\"\$2}' | tr -d '\\\015' >\$_f\n" >$wr
echo -e "\t[ \`grep -il doubleclick \$_f\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\n[ -e \$stor/hosts ] && cat \$stor/hosts >>\$_f" >>$wr
echo -e "if [ -e \$xcl ] ; then\n\twhile read khost ; do\n\t\tsed -i -e \"s/$_rogue\\\t\${khost}/#/\" \$_f\n\tdone < \$xcl\nfi\nkillall -HUP dnsmasq" >>$wr
chmod +x $wr
$wr &


It will create a script called write_dlhosts in /tmp If you want to look at the code in a more readable form you should look at that one first

Happy testing...

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.