Monday 3 October 2011

Running Series: Little Tweaks, Tips and Apps (Part 4)


It’s been awhile since the last post, this edition deals with a very simple problem of universally blocking domains. While this is something often handled by ad and popup blockers etc., I prefer the platform-independent and much more direct host-blocking.
The nice thing advantage here is that we can also block things like in-game advertisements and connection attempts that ad and popup blockers cant get to. The idea is to leverage the built in system’s HOSTS file. In lay terms, it means we can designate something like www.mybadlink.com to point to a black hole instead of directing us to the site.

Users can manually edit the HOSTS file (at your own risk of course), by opening the file using a text editor like notepad. Just run the following shortcut:
notepad %SystemRoot%\system32\drivers\etc.\hosts
We can add additional mappings by scrolling to the bottom and adding them manually using the following template:
127.0.0.1 www.mybadlink.com
What this does is route the request to the bad link to the IP address 127.0.0.1 which represents the user’s current machine. In most cases, the user’s machine won’t be running a web server of any kind so the bug stops there. In the event that the user is running a web server, they [hopefully] won’t be hosting the malicious files that the bad link is trying to access. Some people prefer, instead of 127.0.0.1 to use 0.0.0.0 which literally points the bad link to a null black hole instead of the local server.

This is really tedious to manually kill domains and IPs. So I made a little tool to do this: HostKiller.




You can run this as an application or parametrically. When you run it as an application, you can opt to block multiple domains directly, one per line. If you run it from the parametrically, you can pass a single domain to block. It will automatically block the domain with and without the www. prefix. To use it parametrically simply put the executable (or a shortcut to it) in a location accessible to the system PATH and call:
hostkiller mybadlink.com
If you’ve opted to use a shortcut instead of the executable directly, then replace hostkiller with whatever name you’ve used (I use “hk” as it’s much shorter to type). I’ve thrown in the option to attempt to clean up the HOST file in the event that you have duplicate entries etc.. You shouldn’t need to use this very often (I would hope!). There’s also an app.config file that I’ve included for more advanced users to tinker with some of the available options.

Keep in mind that this won’t necessarily block the bad domain immediately – you’ll often have to close your browsing (or gaming or whatever) session and clear out temporary files for it to actually kick in – but when it does, it will be blocked across the board.

No comments:

Post a Comment