PC Magazine - November 2, 2004 (Updated here, but not on pcmag.com, to fix broken link to BlackHoleProxy)
No-Cost Ad Blocking

By Sheryl Canter

You can block distracting, privacy-invading Web site ads with tools that come with your computer—no need to buy a thing. One way is by editing the Windows HOSTS file (see "Block Web Ads" at http://go.pcmag.com/blockwebads). A less-known but more powerful method is through a Proxy Automatic Configuration (PAC) file, a feature of all modern browsers. Why would you want to use these do-it-yourself methods rather than simply buy inexpensive software that does it automatically? One reason is you like getting your hands dirty and learning how things work. Another is you might find this gives you more configuration options, letting you more easily customize the ad blocking.

Both HOSTS and PAC files block ads by redirecting ad server requests, but HOSTS files can only block entire sites, while PAC files can block URLs within a site. This is important because some companies that serve ads also serve content you would not want to block. For example, the ad server akamai.com also provides streaming media for many Web sites, including Microsoft, for whom it handles Windows Updates. If you block akamai.com, you won't be able to access Windows Updates.

HOSTS files have other limitations. Because each ad server is listed separately, HOSTS files can get so long that they slow the system. PAC files can be much shorter because they support regular expressions (strings that describe whole sets of strings via wildcards and special characters). HOSTS files are bypassed on systems using proxy servers, but PAC files are not. If your computer is running a Web server, there are problems in redirecting ads with a HOSTS file that don't exist with a PAC file.

PAC files were introduced by Netscape with the release of JavaScript in 1996. They consist of a file saved with the extension .pac that defines the JavaScript function FindProxyForURL(). If your browser is configured to use a PAC file (we'll see how below), FindProxyForURL() is called for every URL accessed, even if JavaScript is turned off. The idea of using PAC files to block Web ads was conceived by John R. LoVerso (www.schooner.com/~loverso/no-ads/) while he was documenting security flaws in the first release of JavaScript.

Luckily, you don't need to know JavaScript to use this trick; free ad-blocking PAC files can be downloaded from the Internet. You'll find a good one at www.sherylcanter.com/articles/pac-file.zip. If you'd like to learn how an ad-blocking PAC file is constructed, take a look at the comments within this file. Open it in WordPad as NotePad won't show the line breaks.

The blocked sites in this PAC file are redirected to port 3421 of localhost (your own computer) so as not to conflict with any Web servers that might be running on port 80. Redirecting to an unused port like 3421 causes no problems for IE or Mozilla, but Opera will complain that there is no proxy at that address.

To appease Opera, you can run a small, single-purpose Web server that responds to ad requests with a transparent bitmap. This also serves to eliminate the unsightly error messages that appear when the ads aren't found and prevents delays in browsers that take a while to time out when content isn't found.

Blackhole Proxy, written by Larry Wang, does just this. Version 1.0, just released, features an install utility and a configuration program, so you don't have to learn command line options. You can download it free, with source code, at http://s91363763.onlinehome.us/BlackHoleProxy from this Web site (the original link no longer works): program, source code. You don't need the source code unless you're a programmer. If you just want to block ads, everything you need is in the program zip.

There is no transparent bitmap in the package, but one is included in www.sherylcanter.com/articles/pac-file.zip. The package uploaded to this site includes the transparent bitmap so you no longer need this file.

To use Blackhole Proxy with a HOSTS file, you must change the port from the default of 3421 to 80. Blackhole Proxy is unique in its ability to configure the port. Also, since it can accept connections from other computers, it can be shared on a network.

Once you have Blackhole Proxy loaded, you can configure your browser to use the PAC file. In IE, open Internet Options from the Tools menu, select the Connections tab, then click on Settings or LAN Settings, depending on how you connect to the Internet. In the resulting dialog, check the box Use automatic configuration script, and enter the filename with a syntax like file://C:/PacFiles/ad-block.pac. Then below that, check the box for using a proxy server. In the Address field, type (the IP address for localhost), and for Port enter 3421.

If you're using Internet Explorer, you have to change two additional settings. First, click on the Security tab, select Local intranet, click on the Sites button, and uncheck the box labeled Include all sites that bypass the proxy server.

Second, you must turn off the auto proxy caching mechanism, which prevents the restriction of some server content while allowing other content. Microsoft didn't provide an interface to this setting, but you can use a clever .REG (Registry) file, written by Bill Talcott (www.schooner.com/~loverso/no-ads/IE-auto-proxy-cache.reg), that lets you change the option and add a check box for it on the Advanced page of the Internet Options dialog.

Last but not least, remember to clear your browser's cache after setting up your PAC file. If you don't, the ads will be retrieved from your cache.

HomeWritingSpeakingWeb DesignGraphic DesignBioBlogContact