Tuesday, April 20, 2010

Blocking ads and other various websites

Have you ever been to a site that had one of those very annoying embedded ads that just hung at the top or bottom of the page. This 'banner' was just in the way no matter what you did. Have you ever wanted to get rid of it?

I use various browsers when browsing the web, some support adblock and others do not. I'm not a fan of browser plugins. I'm under the firm belief that a browser is a browser and should only deal with the I/O of html. That being said, I don't use adblock, noscript or anything else like that. I use settings in /etc/hosts to block my ads.

So for today's example, turn off your adblock utility and navigate over to www.unixporn.com. Now you should see a very annoying banner ad on every single page, even on the pages where your viewing a screenshot full screen. Lets get rid of this ad.

OK, from the information in the ad, we know that it is hosted by godaddy. So we'll try the easiest thing first, open up the page source, and search for the term 'godaddy'.
lynx -source www.unixporn.com | grep godaddy
this will give you this line:
script language="javascript" src="https://a12.alphagodaddy.com/hosting_ads/gd01.js">



Now that was pretty easy. Lets add this to /etc/hosts.

# echo '127.0.0.1 a12.alphagodaddy.com' >> /etc/hosts

Restart your browser, and navigate back to unixporn. Tada... the ad is gone. Lets add a site to block. I'm not a fan of social networking so this seems appropriate to me. 


# echo '127.0.0.1 myspace.com' >> /etc/hosts
Restart the browser, and navigate to myspace. If all went well, you should get an error about not being able to load the page. Wonderful isn't it?




You can get a head start on adding lists like this to /etc/hosts by browsing through your adblock lists. The really nice thing about blocking ads/websites this way is that unlike using an adblock plugin inside a browser such as firefox or chromium, this is a system wide setting. You no longer have any need to run adblock.

No comments:

Post a Comment