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 ... 10, 11, 12 ... 17, 18, 19  Next
Author Message
uziq
DD-WRT User


Joined: 02 Jan 2008
Posts: 65

PostPosted: Tue Aug 19, 2008 19:54    Post subject: Reply with quote
This is working great so far. :D

I'm not sure of the best way to have it redirect to a custom server, but this works for me:
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/192.168.1.2/g' -e 's/[[:space:]]*#.*$//' -e '2,\$s/192.168.1.2  localhost$/127.0.0.1  localhost/g' | grep -e 127.0.0.1 -e 192.168.1.2 > /tmp/hosts\nlogger DOWNLOADED http://www.mvps.org/winhelp2002/hosts.txt\nkillall -1 dnsmasq" > /tmp/dlhosts
chmod 777 /tmp/dlhosts
/tmp/dlhosts
fi
ln -s /tmp/hosts /etc/hosts
echo "45 23 * * 5 root /tmp/dlhosts" >> /tmp/crontab

Just replace 192.168.1.2 with your server address (mine is just a computer on the LAN). One odd side-effect is that under the Status -> LAN tab, the server IP shows up as having "xvids-db.com" for the host name (xvids-db.com is the last entry in the hosts file), whereas before, it was the computer's name. Any ideas why it does that? I'm sure it has something to do with the hosts redirecting to 192.168.1.2.

Anyway, here's a small server I made which listens on port 80. It's for Windows only and you will need to allow it thru the firewall (LAN traffic only is recommended). The main intent is to return a blank response so that the webpage won't show an error for the blocked ads. I didn't bother returning a 1x1 pixel or anything for images, because it doesn't seem to be needed. A nice bonus to using this little server is that it will log all the ad hosts that have been encountered. I wish DD-WRT had some kind of built-in server like this, but this works for me since I almost always leave the "server" computer on.

--------------------------------------------
edit: updated AdServer.

v1.03: Now serves a transparent 1x1 gif/png whenever possible. Removed some debugging code.
v1.02: Fixed "unknown host" issue. Improved speed.
v1.01: The AdServer_Hosts.txt file has been renamed to AdServer.dat. Improved column sorting behavior.

TIP: right-click on the textbox or listview for additional options.



AdServer_1.03.zip
 Description:
A small server for Windows.

Download
 Filename:  AdServer_1.03.zip
 Filesize:  45.93 KB
 Downloaded:  921 Time(s)



Last edited by uziq on Mon Aug 25, 2008 21:50; edited 3 times in total
Sponsor
RCShadows
DD-WRT User


Joined: 17 Aug 2008
Posts: 437

PostPosted: Thu Aug 21, 2008 13:04    Post subject: Reply with quote
I booted my router this morning and the ad block script stopped working. Since I am a noobie at this router script stuff I was wondering if I could get some suggestions on what to check for to trouble-shoot this.

Any help appreciated.

Chris
RCShadows
DD-WRT User


Joined: 17 Aug 2008
Posts: 437

PostPosted: Thu Aug 21, 2008 16:04    Post subject: Reply with quote
I got it working again but I had to reset my router and reconfigure. All is well now : \

Chris
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Thu Aug 21, 2008 22:03    Post subject: Reply with quote
There's no reason to make this script "sticky".
It bluntly and selfishly overwrites the original /tmp/hosts
All my local hosts were in there....

_________________
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)
TexasFlood
DD-WRT User


Joined: 17 Jun 2006
Posts: 335

PostPosted: Fri Aug 22, 2008 5:45    Post subject: Reply with quote
uziq wrote:
Anyway, here's a small server I made which listens on port 80. It's for Windows only and you will need to allow it thru the firewall (LAN traffic only is recommended). The main intent is to return a blank response so that the webpage won't show an error for the blocked ads. I didn't bother returning a 1x1 pixel or anything for images, because it doesn't seem to be needed. A nice bonus to using this little server is that it will log all the ad hosts that have been encountered. I wish DD-WRT had some kind of built-in server like this, but this works for me since I almost always leave the "server" computer on.
Cool. Thanks. I'd been using pixelserv and was thinking about posting about that. Pixelserv (I used v1.0) is perl so you can run it either with free version of ActivePerl or compile it with perl2exe. But your program is an intriguiing alternative that I'm going to try for a bit.
uziq
DD-WRT User


Joined: 02 Jan 2008
Posts: 65

PostPosted: Sun Aug 24, 2008 18:31    Post subject: Reply with quote
AdServer has been updated in my previous post.
TexasFlood
DD-WRT User


Joined: 17 Jun 2006
Posts: 335

PostPosted: Sun Aug 24, 2008 21:02    Post subject: Reply with quote
uziq wrote:
AdServer has been updated in my previous post.
As I said before, pretty cool. One minor comment, do you think it would be possible to list the IP address for sites that don't resolve? I have some "{unknown}" entries that really don't tell me anything. Or maybe still say "(unknown)" if it doesn't resolve but just add a column and include IP address so that info is availble as well? Thanks again, not meant as criticism, just hopefully constructive feedback.
uziq
DD-WRT User


Joined: 02 Jan 2008
Posts: 65

PostPosted: Sun Aug 24, 2008 21:33    Post subject: Reply with quote
TexasFlood wrote:
do you think it would be possible to list the IP address for sites that don't resolve? I have some "{unknown}" entries that really don't tell me anything.

AdServer simply extracts the host field from the http headers. But sometimes there isn't a host and the headers look like a bunch of gibberish. I call those cases "unknown".

For example, here's the headers that AdServer sees when you load digg.com:
Quote:
GET /HG?hc=&hb=DM5610162LBA38EN3&cd=1&hv=6&n=Digg%20-%20All%20News%2C%20Videos%2C%20%26%20Images&con=
&vcon=/&tt=auto&ja=y&dt=16&zo=300&lm=1219612899000&bn=Netscape&ce=y&ss=1680*1050&sc=32&sv=16&cy=u&hp=u
&ln=en-US&vpc=HBX0200u&vjs=HBX0201.03u&hec=0&pec=&cmp=&gp=&dcmp=&dcmpe=&dcmpre=&cp=null&fnl=&seg=1&epg=
&cv=&gn=&ld=&la=&c1=&c2=&c3=&c4=&customerid=&ttt=lid,lpos&ra=&pu=&rf=bookmark
&pl=Mozilla%20Default%20Plug-in%3AQuickTime%20Plug-in%207.3%3AQuickTime%20Plug-in%207.3%3AQuickTime%20Plug-
in%207.3%3AQuickTime%20Plug-in%207.3%3AQuickTime%20Plug-in%207.3%3AShockwave%20for%20Director%3A2007
%20Microsoft%20Office%20system%3AShockwave%20Flash%3ASilverlight%20Plug-
In%3AVLC%20Multimedia%20Plugin%3AJava%28TM%29%20Platform%20SE%206%20U2%3AJava%28TM%29%20Platform%20SE
%206%20U2%3AJava%28TM%29%20Platform%20SE%206%20U2%3AJava%28TM%29%20Platform%20SE%206%20U2%3AJava
%28TM%29%20Platform%20SE%206%20U2%3AJava%28TM%29%20Platform
%20SE%206%20U2%3AJava%28TM%29%20Platform%20SE%206%20U2%3AMicrosoft%AE%20DRM
%3AWindows%20Media%20Player%20P

It doesn't contain a host and I don't know why.


On the other hand, here an example of a typical request which contains a host field:
Quote:
GET /pagead/show_ads.js HTTP/1.1
Host: pagead2.googlesyndication.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16
Accept: */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.dd-wrt.com/phpBB2/viewforum.php?f=1
Cache-Control: max-age=0


edit: nevermind. the problem is that I was only looking at the first 1024 chars of the buffer. The next version will look at everything.
TexasFlood
DD-WRT User


Joined: 17 Jun 2006
Posts: 335

PostPosted: Sun Aug 24, 2008 22:00    Post subject: Reply with quote
Thanks! I saw the symptom Idea but clearly misdiagnosed the root problem Question . But looks like you sorted it out, Very Happy
RCShadows
DD-WRT User


Joined: 17 Aug 2008
Posts: 437

PostPosted: Sun Aug 24, 2008 22:04    Post subject: Reply with quote
I appreciate what you have done with your program. However, it really makes things slow. That may be the 1.6gHz server I am using for it but is there any way to just send a blank page without the graphics or maybe some info like IP address where the ad would go?

Chris
uziq
DD-WRT User


Joined: 02 Jan 2008
Posts: 65

PostPosted: Mon Aug 25, 2008 1:44    Post subject: Reply with quote
Updated AdServer again.

RCShadows wrote:
I appreciate what you have done with your program. However, it really makes things slow. That may be the 1.6gHz server I am using for it but is there any way to just send a blank page without the graphics or maybe some info like IP address where the ad would go?

It sends a blank character, and as of v1.02 it also responds with these headers...
Quote:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1
Connection: close

I still haven't seen the need to send blank images yet, so for now I'll just stick with the blank character.

It also runs quicker. Let me know if you have any more problems with it.
uziq
DD-WRT User


Joined: 02 Jan 2008
Posts: 65

PostPosted: Mon Aug 25, 2008 21:53    Post subject: Reply with quote
Updated AdServer.

I think it might need its own topic/thread before too long. Razz
RCShadows
DD-WRT User


Joined: 17 Aug 2008
Posts: 437

PostPosted: Sat Aug 30, 2008 4:02    Post subject: **** UPDATE **** Reply with quote
I am part of the MS Beta for Internet Explorer 8. The pages blocked by this fine code are now displayed a little nicer by default. It still says "Internet Explorer couldn't...." but it looks nicer and is acceptabile for me on my home network.

Thanks to all of those that came up with this....kudos! It works great!

Chris
cyberde
DD-WRT Guru


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

PostPosted: Sat Aug 30, 2008 8:58    Post subject: Reply with quote
Why not use the mini_httpd for dd-wrt, the one bwlog uses? That way you'll be able to run the adserver on your router Smile
_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
threepwood
DD-WRT Novice


Joined: 01 Aug 2008
Posts: 2

PostPosted: Sat Aug 30, 2008 15:09    Post subject: Reply with quote
Yeah, it would be great if we could run AdServer through mini_httpd.

Nevertheless, it's working great atm!
Goto page Previous  1, 2, 3 ... 10, 11, 12 ... 17, 18, 19  Next Display posts from previous:    Page 11 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