Do not waist your broadband on needless stuff

Every time you go on the Internets*, your web-browser are using a lot of your broadband on loading ads, scripts and images from 3rd-party domains. But you can stop this! - and get back the speed you want for browsing the websites you like.

With the scripts below you can now block domains that serve ads and other unwanted web-content. This will result in faster browsing, mainly because your browser are not allowed to access these domains and there by not having to load ads, scripts, Flash movies or big images. You can even block the ads within YouTube movies (some geeking and ninja-tricking may be required).

These scripts are ideal for Parental Control. Blocking a website simply result in an error message or a blank image. As these script require administrative credentials, children can not remove the blocks, disable the ad-blocking extension or install another web-browser without an ad-blocking extension. All web-traffic to the blocked domain are denied. Not even the system itself are allowed to access the domains.

If the web-service does not have a domain name, but only an IP-number,

Note: Domains and subdomains are seperate domains and blocking the first does not block latter. Ie. blocking doubleclick.net does not block ad.doubleclick.net nor www.doubleclick.net. (For Windows users, please read edit-note for script.)

* Yes, plural :) Just look it up!


How to do

(These scripts should only be used by trained administrators who know what they are doin... wait... that excludes you... DOH! Just use with caution, ok? ...and don't complain if you mess up your system!)


Mac OS X : AppleScript
  1. display dialog "Enter domain to block" default answer "" buttons {"Cancel", "Next"} default button 2
  2. set domain to the text returned of the result
  3. display dialog "Enter reason to block" default answer "Ad blocking" buttons {"Cancel", "Block"} default button 2
  4. set reason to the text returned of the result
  5. if domain is not "" and reason is not "" then
  6. do shell script "/usr/bin/printf \"# " & reason & "\\n127.0.0.1\\t" & domain & "\\n\" >> /etc/hosts; /usr/bin/dscacheutil -flushcache" with administrator privileges
  7. end if

  1. Copy script and insert in new document in AppleScript Editor (located in your Application or Utilities folder)
    OR... Download the script below and open in Apple Script Editor
  2. Click Compile - if you copy text correctly, no error should occur. If you get error, go to item #1 in this list!
  3. Save document as an Application where-ever your like (mine is on the Desktop for easy access).

 Download the AppleScript 'Domain-Blocker.scpt' here

Note:
When launching your newly created Domain-Blocker.app, you will be asked to provide Administrator credentials. If you do not have this, please consult your administrator, as this script will not work otherwise.
Windows 7 : Batch-script
  1. @ECHO off
  2. SET NEWLINE=& echo.
  3. SET /p blockthis="Enter site to block: "
  4. IF "%blockthis%"=="" exit
  5. ECHO.
  6. FIND /C /I "%blockthis%" %WINDIR%\system32\drivers\etc\hosts 1>nul
  7. IF %ERRORLEVEL% NEQ 0 GOTO blocksite
  8. ECHO Site already blocked
  9. GOTO doexit
  10. :blocksite
  11. ECHO ^%NEWLINE%127.0.0.1 %blockthis%>>%WINDIR%\system32\drivers\etc\hosts
  12. ipconfig /flushdns
  13. nbtstat -R
  14. ECHO Site now blocked, but DNS may still be cached by browsers.
  15. :doexit
  16. ECHO.
  17. PAUSE

  1. Copy script and insert in new document in Notepad (located in your Accessories folder)
  2. Save document where-ever your like (mine is in the My Documents)
  3. Create a Shortcut on the Desktop. Right click the shortcut and select Properties. Click the Advanced button. Check on the option Run as administrator. (Click OK to apply changes, and Ok again to close the Properties window)
 Download the Batch-file 'Domain-Blocker.cmd' here

Note:
When launching your newly created Domain-Blocker.cmd, you will be asked to provide Administrator credentials. If you do not have this, please consult your administrator, as this script will not work otherwise.

Edit:
After blocking a domain like ad.doubleclick.net, this script can not block other domains of higher level. This is because the script are seaching the existing hosts-file for matching text, not for matching lines. So... if you already blocked a domain like ad.doubleclick.net, you can not also block doubleclick.net. Unless... 1) You block google.com then block ads.google.com, or... 2) remove lines 8 through 15 in the script. Then all domains entered will be added to the hosts-file, even if the domains are already added (messy, but will work anyway).
Linux : shell-command
  1. $> sudo /usr/bin/printf "127.0.0.1\\tDOMAIN_GOES_HERE\\n" >> /etc/hosts

Note:
I'm not a Linux user, so please forgive me if this is not 100% correct.
If you're a Linux user, you probably already know how to do this ;)

Edit:
You probably also need to flush the cache as done on Mac OS X using this command line:
  1. $> sudo /usr/bin/dscacheutil -flushcache

Examples


FAQ



All information on this page expires: Yesterday