Safari Can’t Connect to the Server

Do not waste your broadband on needless downloads

Every time you browse on the Internets* using your favorite web-browser, you are using a lot of your broadband for loading ads, tracking-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.* Yes, plural :) Just Google it!

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

These scripts are ideal for Parental Control. Attempting to access a blocked website simply result in a blank page, a missing image or an error message. As these script require administrative credentials, children can not remove the blocks, disable the ad-blocking extension or install a new web-browser without an ad-blocking extension. All web-traffic to the blocked domains is denied by the OS. Not even other apps or system tools are allowed to access the domains.

Note: If the unwanted web-service does not have a domain name, but only an IP-number, you can not use this kind of blocking. You should block it via the build-in Firewall (Windows), via the Network-settings (Mac), or if possible in your Internet-Router’s configuration.

How it works

The hosts-file is a part of the base-system of most modern computers operating system (OS) and deal with the computers ”translation” from URLs to IP-address (DNS) when accessing the Internets. Normally this are done via your Internet Service Provider’s DNS-servers, but you can bypass this request by editing the hosts-file – essentially telling your browser to load the content from another server. When the content can not be found at the new location (your localhost) the browser skips the loading of the content.

How to do

These scripts should only be used by trained administrators who know what they are doing... wait... that might exclude you... DOH! Just use with caution, ok?

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; sudo /usr/bin/killall -HUP mDNSResponder" with administrator privileges
  7. end if

  • Copy the text above and insert it into new document in Script Editor (located in your Applications / Utilities folder)
  • Click Compile - if you copy text correctly, no error should occur. If you get an error, start from the ”Copy the text above...”-part in this list!
  • Save the document as an Application where-ever your like (mine is on the Desktop for easy access).

    <-- I miss Aqua (the Mac GUI, not the music group)

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.
* Restarting your Mac may be necessary, or at least relaunching of browser(s) and clearing their cache :/
Windows 7-10 : Batch-script
  1. @ECHO off
  2. SET NEWLINE=& echo.
  3. SET /p blockthis="Enter site to block: "
  4. IF "%blockthis%"=="" exit
  5. ECHO.
  6. ECHO ^%NEWLINE%127.0.0.1 %blockthis%>>%WINDIR%\system32\drivers\etc\hosts
  7. ipconfig /flushdns
  8. nbtstat -R
  9. ECHO Site now blocked, but DNS may still be cached by browsers.
  10. PAUSE

  • Copy script and insert it into new document in on the Desktop for easy access.
  • Name the script something like Domain-Blocker.cmd
  • To use: Right click the script and select Run as Administrator or it will not work.
    Cleaning the DNS-cache requires Administrator rights, so if you don’t have Administrative rights the domain will not be blocked until the DNS-cache is cleaned or expires (most likely when system is restarted).

This script does not check if a domain is already blocked, so duplicates may exist in your hosts-file. It should work just fine anyway.

Linux : shell-command
  1. $> sudo /usr/bin/printf "127.0.0.1\\tDOMAIN_GOES_HERE\\n" >> /etc/hosts
  2. $> sudo /usr/bin/dscacheutil -flushcache

Note:
I’m not really a Linux user, and there are many different distro’s out there, so please forgive me if this is not 100% correct.
If you’re a Linux user, you probably already know how to do this anyway ;)


Assembled in a bash-script with multiple argument support:
  1. #!/usr/bin/env bash
  2. [ "$#" -lt 1 ] && printf "At least 1 domain is required\n" && exit
  3. for domain in "@0"
  4. do
  5. sudo /usr/bin/printf "127.0.0.1\\t$domain\\n" >> /etc/hosts
  6. done
  7. sudo /usr/bin/dscacheutil -flushcache
  • Save script somewhere convenient for you, and name it something like `blocker.sh`.
  • Make script executable: $> chmod +x blocker.sh
  • To use: $> ./blocker.sh www.pokerstars.com
  • or this: $> sh blocker.sh www.pokerstars.com pokerstars.com
  • or this: $> bash blocker.sh www.pokerstars.com pokerstars.com facebook.com

Examples of domains to block


FAQ



All information on this page expires: Yesterday