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, 4 ... 17, 18, 19  Next
Author Message
HowardZ
DD-WRT Guru


Joined: 18 Jun 2007
Posts: 706
Location: Maryland

PostPosted: Fri Sep 21, 2007 12:58    Post subject: Reply with quote
redhawk0 wrote:
HowardZ....use the dos2unix command.....it will remove all the ^M characters at the end of the lines.

This is done in unix of course.

redhawk


I fixed it by adding to the sed command :
Quote:

#!/bin/sh
wget -O - http://www.mvps.org/winhelp2002/hosts.txt | \
grep 127.0.0.1 | \
sed -e '2,$s/127.0.0.1/0.0.0.0/g' -e 's/^M//g' -e 's/[[:space:]]*#.*$//' \
> /etc/hosts


When using the vi editor,
to enter the ^M, one types ctrl-v and then ctrl-m.
do not enter a "^" followed by a "M" - that won't do it.

The only messy thing left is that the host file begins with a single blank line.


Last edited by HowardZ on Fri Sep 21, 2007 13:26; edited 1 time in total
Sponsor
speedy3k
DD-WRT User


Joined: 19 Apr 2007
Posts: 180

PostPosted: Fri Sep 21, 2007 13:17    Post subject: Reply with quote
logger WAN UP Script Executing
sleep 5
test -s /tmp/dlhosts
if [ $? == 1 ] ; then
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:]]*#.*$//' > /etc/hosts\nlogger DOWNLOADED http://www.mvps.org/winhelp2002/hosts.txt\nkillall -1 dnsmasq" > /tmp/dlhosts
chmod 777 /tmp/dlhosts
/tmp/dlhosts
fi
cru a Gethosts "45 23 * * 5 /tmp/dlhosts"



I added tr -d '\015\032' to remove the ^M. it works well too.
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Fri Sep 21, 2007 16:14    Post subject: Reply with quote
Well the script posted by speedy3k works, even when I customised it to my needs.
For the ones that complain it doesn't work. You must be doing something wrong, really :o

I don't think that dnsmasq needs to be restarted right?

_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
infusion
DD-WRT Guru


Joined: 30 Aug 2006
Posts: 506

PostPosted: Fri Sep 21, 2007 16:46    Post subject: Reply with quote
I got it working. Some ads show "the page cannot be displayed", other still shows...

Adblock seems to work better, removing more ads and in a neat way.

You get the same results?
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Fri Sep 21, 2007 17:11    Post subject: Reply with quote
Yes, some ads still show up, that's why I'm including my own host-file too :)

The "the page cannot be displayed" problem displays when a website tries to load another website into an iframe, resulting in that error. Other sites, which show ads by the <img> tag give good results.
Now I'm using FF Adblock and this way too, so IE clients have less ads to.

_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
moreins
DD-WRT User


Joined: 18 Nov 2006
Posts: 320
Location: Cali, Colombia

PostPosted: Sun Sep 23, 2007 2:53    Post subject: Reply with quote
hello
thanks for al the info given...i have some questions, i hope anyone can give me the answers:

1)if i implement this script in my router, would it be the same than having Firefox's Adblock Plus installed on my hosts???
2)should i add the script to the router as a firewall script or a startup script?
3)do i have to reboot the router after i add the script?
4)do i have to enable DNSMasq on the router???
5)i have tried the scripts posted here but i have lots of doubts regarding the code itself? can anyone please post a working script using the code tag?
Code:
code tag

6)when i add the script to the router, the router downloads a txt file of approx. 700KB...where does this file is stored?

thanks in advance...

moreins

_________________
WRT54GS v2.1 > v24-sp2 (01/01/09) mega
WRT54GS v5 > v24-sp2 (01/01/09) micro
PPTP, WDS link and SD Mod
speedy3k
DD-WRT User


Joined: 19 Apr 2007
Posts: 180

PostPosted: Sun Sep 23, 2007 4:24    Post subject: Reply with quote
Code:

logger WAN UP Script Executing
sleep 5
test -s /tmp/dlhosts
if [ $? == 1 ] ; then
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:]]*#.*$//' > /etc/hosts\nlogger DOWNLOADED http://www.mvps.org/winhelp2002/hosts.txt\nkillall -1 dnsmasq" > /tmp/dlhosts
chmod 777 /tmp/dlhosts
/tmp/dlhosts
fi
cru a Gethosts "45 23 * * 5 /tmp/dlhosts"


now to answer some of your questions
1. no..this does not work the same as firefox ad blocker. this will work with any browser since the ads (on the list) are being blocked at the router.
2. I have mine saved as a startup script
3. I do
4. yes..DNSMasq and Local DNS should be enabled
5. done...just copy and paste
6. its stored in the tmp folder as "hosts"
maybe some questions you thought of, but didn't ask

7. the cru job runs at 23:45 on friday to update the list. you can change that to whatever you want. the spot for 45 = min, 23 - hour and 5 =day of week (sun=0 Friday-5)
8. if you want to use a list from somewhere else, just change the url in the script.
moreins
DD-WRT User


Joined: 18 Nov 2006
Posts: 320
Location: Cali, Colombia

PostPosted: Sun Sep 23, 2007 18:17    Post subject: Reply with quote
dude, thanks a lot for all your help...im gonna give it a try as soon as i get home tonight...thanks a lot
i hav one last question....i already have a startup script running in my router...i was wondering how do i handle multiple startup scripts? do i just leave an empy line and add the other script or what???
another thing: regarding your script. are these 2 lines necessary???

Code:
logger WAN UP Script Executing
sleep 5


thanks again

_________________
WRT54GS v2.1 > v24-sp2 (01/01/09) mega
WRT54GS v5 > v24-sp2 (01/01/09) micro
PPTP, WDS link and SD Mod
speedy3k
DD-WRT User


Joined: 19 Apr 2007
Posts: 180

PostPosted: Sun Sep 23, 2007 18:37    Post subject: Reply with quote
yeah...just add it to the next line.
as far as the two lines...1 is to add an entry to the log, the other just waits before starting the script for a few seconds before running the rest of the script. they don't hurt anything. I would leave them in, so if you ever enable syslog, you can see that the command are being ran.
nemesisdb
DD-WRT User


Joined: 10 Oct 2006
Posts: 197

PostPosted: Sun Sep 23, 2007 19:03    Post subject: Reply with quote
I have a 16mb model with v24vpn installed. I don't have much free memory at the moment (around .5 to .Cool. Am I correct in assuming that I can't do this? Any alternative ways of doing it?
speedy3k
DD-WRT User


Joined: 19 Apr 2007
Posts: 180

PostPosted: Mon Sep 24, 2007 5:25    Post subject: Reply with quote
nemesisdb wrote:
I have a 16mb model with v24vpn installed. I don't have much free memory at the moment (around .5 to .Cool. Am I correct in assuming that I can't do this? Any alternative ways of doing it?




You should go ahead and give it a try. it might work for you. worse thing that will happen is the file will be to large and wont download.
nemesisdb
DD-WRT User


Joined: 10 Oct 2006
Posts: 197

PostPosted: Mon Sep 24, 2007 5:28    Post subject: Reply with quote
i may next weekend when I have some downtime (in case it does blow something up). I checked the file from that website and it was larger than the lowest free memory that I normally have...

guess i can always look for other services to disable? Smile
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Mon Sep 24, 2007 9:17    Post subject: Reply with quote
You can also save the hosts file on, let's say an SD card and create an symbolic link in /tmp/hosts to /mmc/etc/hosts for example... Should work...
_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
nemesisdb
DD-WRT User


Joined: 10 Oct 2006
Posts: 197

PostPosted: Mon Sep 24, 2007 12:34    Post subject: Reply with quote
cyberde wrote:
You can also save the hosts file on, let's say an SD card and create an symbolic link in /tmp/hosts to /mmc/etc/hosts for example... Should work...


I had that thought as well. Didn't know what kind of performance hit it would be though, since every connection is checked against the file and since the SD card is noticably slower than ram. Also, I haven't seen instructions for the G125. I could also use a network share I assume?
redhawk0
DD-WRT Guru


Joined: 04 Jan 2007
Posts: 11563
Location: Wherever the wind blows- North America

PostPosted: Mon Sep 24, 2007 12:44    Post subject: Reply with quote
Actually...there is a thread running right now regarding G125 and SD/MMC mod.

http://www.dd-wrt.com/phpBB2/viewtopic.php?t=20548

redhawk

_________________
The only stupid question....is the unasked one.
Goto page Previous  1, 2, 3, 4 ... 17, 18, 19  Next Display posts from previous:    Page 3 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