Ad-blocking with DD-WRT

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page Previous  1, 2, 3 ... 12, 13, 14 ... 17, 18, 19  Next
Author Message
mchipser
DD-WRT User


Joined: 14 Jun 2006
Posts: 122
Location: Texas

PostPosted: Thu Oct 09, 2008 0:56    Post subject: blocked pages Reply with quote
is there a way to block the "unable to connect" section..

Myk3

_________________
Linksys WRT600N as AP v24
ASUS RT-N16 Client Bridge
Lafonera as travel AP
Sponsor
es1013
DD-WRT Novice


Joined: 08 Oct 2008
Posts: 17

PostPosted: Thu Oct 09, 2008 1:51    Post subject: Re: ad block - tried everything Reply with quote
*sorry about the double-post before

Seems like there's too many commands missing from BusyBox in the micro version - nget, tr, sed, ln. Would wget work? I couldn't really find any documentation on nget online.

Maybe I can manually format the hosts file, and then upload it instead of retrieving it from mvps. It would be real sweet if we could get this to work on all dd-wrt versions.

Thanks for the help so far.


Last edited by es1013 on Thu Oct 09, 2008 12:33; edited 1 time in total
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Thu Oct 09, 2008 6:25    Post subject: Reply with quote
root@WAN:/tmp# ln -s /tmp/hosts /etc/hosts
ln: /etc/hosts: File exists

But there's no need to run this command.
That symbolic link already exists. There's no need to run that command again.
The author somehow thinks this link has to be refreshed...

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
speedy3k
DD-WRT User


Joined: 19 Apr 2007
Posts: 180

PostPosted: Thu Oct 09, 2008 7:33    Post subject: Reply with quote
here you go
someone was wanting a way that would prevent host from getting overwritten. this is how you do it.
Code:

echo -e "#!/bin/sh\nwget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 | tr -d '\015\032' | sed -e '2,\$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//' > /tmp/adblock\nlogger DOWNLOADED http://www.mvps.org/winhelp2002/hosts.txt\nkillall -1 dnsmasq" > /tmp/dlhosts
chmod 777 /tmp/dlhosts
/tmp/dlhosts
fi
echo "30 18 * * 1 root /tmp/dlhosts" >> /tmp/crontab

notice "ln" has been removed. this was not needed since /etc is read only.

now, under DNSMasq add this to "Additional DNSMasq Options"
Code:

addn-hosts=/tmp/adblock


thats it. now it will block ads, and still keep your host file.
enjoy
speedy3k
DD-WRT User


Joined: 19 Apr 2007
Posts: 180

PostPosted: Thu Oct 09, 2008 7:38    Post subject: Reply with quote
oh yeah..to the guy that wanted to know what this does
Code:

tr -d '\015\032


it removes the ^M (carriage return) from end of the downloaded host file.
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Thu Oct 09, 2008 10:00    Post subject: Reply with quote
That's a better solution, but I still think the cronjob is close to useless....
_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
veryoldschool
DD-WRT Novice


Joined: 09 Oct 2008
Posts: 1

PostPosted: Thu Oct 09, 2008 14:42    Post subject: cron job Reply with quote
speedy3k wrote:
here you go
someone was wanting a way that would prevent host from getting overwritten. this is how you do it.
Code:

echo -e "#!/bin/sh\nwget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 | tr -d '\015\032' | sed -e '2,\$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//' > /tmp/adblock\nlogger DOWNLOADED http://www.mvps.org/winhelp2002/hosts.txt\nkillall -1 dnsmasq" > /tmp/dlhosts
chmod 777 /tmp/dlhosts
/tmp/dlhosts
fi
echo "30 18 * * 1 root /tmp/dlhosts" >> /tmp/crontab

notice "ln" has been removed. this was not needed since /etc is read only.

now, under DNSMasq add this to "Additional DNSMasq Options"
Code:

addn-hosts=/tmp/adblock


thats it. now it will block ads, and still keep your host file.
enjoy


speedy3k's instruction worked perfectly except that in my case /etc/crontab didn't get altered by the startup script. I used the gui field
Administration->Management-> additional cron jobs
as a workaround and added :
33 10 * * 4 root /tmp/dlhosts
to get cron job in /etc/cron.d/cron_jobs
Also, the whole thing (obviously?) only worked AFTER I removed the DNS entries in my Mac's network setup. (Sys Pref-> Network->advance->DNS)

Thanks for the great work guys.
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Thu Oct 09, 2008 20:45    Post subject: Reply with quote
Sorry to hijack it, but I'm doing it this way:

Put this in startup:
Code:
echo -e "#!/bin/sh\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 | sed -e 's/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*\$//' | tr  ' ' '\\\t' | tr -s '\\\t' | tr -d '\\\015' | grep '^0\\.0\\.0\\.0' | grep -v localhost >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\tif [ \"\`grep -c doubleclick /tmp/dlhosts\`\" -ne \"0\" ]; then\n\t\tbreak\n\tfi\n\tsleep 60\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

Add to "Additional DNSMasq Options"
Code:
addn-hosts=/tmp/dlhosts


As I said before... The idea is good, but the implementation imho is flawed. Some things are done that are not needed and some things that are needed are not done.

The script will write a script that results in this code:
Code:
#!/bin/sh
while true
do
        wget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 | sed -e 's/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//' | tr  ' ' '\t' | tr -s '\t' | tr -d '\015' | grep '^0\.0\.0\.0' | grep -v localhost >/tmp/dlhosts

        if [ "`grep -c doubleclick /tmp/dlhosts`" -ne "0" ]; then
                break
        fi
        sleep 60
done
killall -HUP dnsmasq

The download is inside an "endless" loop and it will try to download the host file. If it doesn't succeed (the file should contain doubleclick) it will wait a minute and try again. The script is only executed once. afterwards dnsmasq is signalled to reload its config. Do note the ampersand which makes it possible for the router to continue the rest of the startup. Some empty lines are killed, double spaces are converted to single tabs and last but not least.... localhost still is 127.0.0.1

Comments are welcomed...

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Fri Oct 10, 2008 0:07    Post subject: Reply with quote
I think this is even a bit more cleaner....

Code:
echo -e "#!/bin/sh\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | awk '{print \$1\"\\\t\"\$2}' | sed -e 's/127.0.0.1/0.0.0.0/g' | grep -v localhost >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\tif [ \"\`grep -c doubleclick /tmp/dlhosts\`\" -ne \"0\" ]; then\n\t\tbreak\n\tfi\n\tsleep 60\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &


It will write this code:
Code:
#!/bin/sh
while true
do
        wget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep "^127.0.0.1" | awk '{print $1"\t"$2}' | sed -e 's/127.0.0.1/0.0.0.0/g' | grep -v localhost >/tmp/dlhosts

        if [ "`grep -c doubleclick /tmp/dlhosts`" -ne "0" ]; then
                break
        fi
        sleep 60
done
killall -HUP dnsmasq

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
fraterJP
DD-WRT Novice


Joined: 08 Jun 2006
Posts: 5

PostPosted: Sat Oct 11, 2008 8:14    Post subject: Reply with quote
This pixelserv is a great idea so I'm now running it on my fedora on an extra IP. If someone wants to know how, I will write an howto..

By changing "rogue" to another IP where pixelserv is running on port 80, you can speedup browsing even more... I re-added the deleting of the carriage return...

BTW... Anyone knows a "good" site to test???

Code:
rogue=0.0.0.0
echo -e "#!/bin/sh\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | awk '{print \$1\"\\\t\"\$2}' | sed -e 's/127.0.0.1/$rogue/g' | tr -d '\\\015' | grep -v localhost >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\tif [ \"\`grep -c doubleclick /tmp/dlhosts\`\" -ne \"0\" ]; then\n\t\tbreak\n\tfi\n\tsleep 120\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &


This version adds google-analytics.com "by hand" to the extra hostfile... Anyone knows why it isn't in the original file? I added it because it received the most hits in the firefox addon "adblock".
Anyone knows of any other "missing" entries?

Code:
rogue=0.0.0.0
echo -e "#!/bin/sh\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | awk '{print \$1\"\\\t\"\$2}' | sed -e 's/127.0.0.1/$rogue/g' | tr -d '\\\015' | grep -v localhost >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\tif [ \"\`grep -c doubleclick /tmp/dlhosts\`\" -ne \"0\" ]; then\n\t\tbreak\n\tfi\n\tsleep 60\ndone\necho -e '192.168.10.5\\\tgoogle-analytics.com' >>/tmp/dlhosts\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sat Oct 11, 2008 12:43    Post subject: Reply with quote
On second thought...
It is better to save your own blocked hosts in a file called /jffs/hosts and add that too.....

No comments?

If anyone knows some more blocklists I can write something that puts them all together....

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
famewolf
DD-WRT Novice


Joined: 01 Oct 2008
Posts: 31

PostPosted: Sat Oct 11, 2008 17:06    Post subject: Reply with quote
frater wrote:
On second thought...
It is better to save your own blocked hosts in a file called /jffs/hosts and add that too.....

No comments?

If anyone knows some more blocklists I can write something that puts them all together....



I added google-analytics.com to /jffs/hosts and then added it to dnsmasq parms as a 2nd additional hosts file and kept the original looping script..good idea....You would think you could write some sort of rule that would redirect 404's pointing to localhost to a standard image and leave others as normal 404.
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sun Oct 12, 2008 1:08    Post subject: Reply with quote
> You would think you could write some sort of rule that would redirect 404's pointing to localhost to a standard image and leave others as normal 404.

By running a very tiny perl script called pixelserv on port 80 you can use that IP....

All my machines already have a webserver running on port 80, so I added an extra static IP on my Linux-machine and used that to run "pixelserv" on.
http://proxytunnel.sourceforge.net/pixelserv.php

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sun Oct 12, 2008 9:40    Post subject: Reply with quote
cyberde wrote:
Has anyone gotten Pixelserv to run on DD-WRT? That would be the ultimate solution ofcourse Smile


pixelserv needs perl...
But it also needs to be run on port 80 and the webinterface is already running there....

This could be solved by running the webserver on another port which would involve restarting the webserver and the risk it will get restarted by another script...

The easiest thing for me to do was adding an extra IP to my linux-server and run pixelserv on that...

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sun Oct 12, 2008 10:18    Post subject: Reply with quote
Adding a 2nd addn-hosts to /jffs/hosts doesn't work.

Because google-analytics.com was correctly resolved to 192.168.10.5 I thought it was working, but I was still running the version in which I add it 'by hand' int the script.

Due to this presumption I thought it was working but in fact it wasn't. I only found out just now after I added rad.msn.com

So please disregard my post about adding a 2nd dnsmasq.

Maybe it's better to improve this list and host it somewhere on a fast free webserver...
Any suggestions????

Someone already said he was downloading his own file... Can you please comment?

I could write a little script that runs on a server which periodically downloads the script and removes some hosts from an exclude-list and includes some...

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
Goto page Previous  1, 2, 3 ... 12, 13, 14 ... 17, 18, 19  Next Display posts from previous:    Page 13 of 19
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum