There are 3 ways to do this on Mac OS X without requiring you to do a lot more.
- You have already mentioned the first way - using
/etc/hosts
.
- You have also ruled out using the second way - using browser plugins.
- The 3rd way is to use the "Parental Controls" feature under System Preferences.
There is a 4th way - if you are talking about writing code and implementing your own script or your own custom app.
If you are talking about "under the hood" level implementation - i.e. you want to implement a custom application of your own (similar to Little Snitch), then you should get yourself familiar with the concept of iptables
(linux systems routinely use this to control access rights to specific hosts and ports).
In Mac OS (which essentially is FreeBSD under the hood), the equivalent is ipfw
(IP Firewall) and for Mac OS 10.7 onwards, ipfw
has been deprecated in favour of pf
(Packet Filter).
Reference article which you can refer to: http://ikawnoclast.com/security/mac-os-x-pf-firewall-avoiding-known-bad-guys/