Banning domains temporarily from local access I need to control myself. So far, I was using a Windows device for work, where I would simply reroute Facebook, news sites and similar to 127.0.0.1. In near future, I will have to use the same device (running OS X) for both private time and work.

I need a way to “switch off” a set of domains from my machine, similar to what I was doing with the hosts file in Windows. But since it should not be permanent, I also need a way to shut it off again. 

There is no need for a huge blockage that I cannot overcome myself for the next xx hours, I'm not addicted - it's supposed to be against the quick “let's check this news site” reflexes during work time.

Does anyone know of any free software that does this or is able of hacking this into AppleScript quickly?

Bonus: Set up a second routine, that starts the “ban everything” script say 8 AM, and runs the “unban everything” script at 6 PM.
I highly recommend the app SelfControl:
http://selfcontrolapp.com

You can use either a whitelist or a blacklist of websites and you can set it for a specified time limit. It's great for either blocking the sites you know will tempt you, or allowing only certain sites you know you'll need. 

You can also edit the hosts file at /private/etc/hosts to block sites. Here is a site with instructions:
http://www.mactip.net/how-to-edit-the-hosts-file-on-a-mac/


  Similarly, it’s possible to block a harmful domain by mapping it to the localhost. Thereby preventing the computer from reaching the domain. In this situation, map the bad domain to 127.0.0.1. It will not be able to connect.


So all you have to do is add a line like this:

127.0.0.1    badwebsite.com


to your hosts file.