I've recently been made aware of an app called
Freedom, which basicaly shuts down your Internet connection for a time. This is supposed to enhance your productivity, by keeping you from wasting time on the Internet. That's silly, I thought, why not just exercise some self control? Then I realised I don't have that much self control, so I had a look at the app. It turns out it costs $10, however, which I thought was a bit steep for something I could probably do as a one-liner in bash, so I decided to figure out how it works, or at least how I could do something similar.
At first, I thought about deactivating the network cards, which is pretty trivial from the terminal, at least on the Mac, and I guess it's the same on linux. Just type
sudo ifconfig en0 down
sudo ifconfig en1 down
to turn off both the wireless and the wired network. If you're on wired network, this works quite nicely, as most OSes don't have a convenient button to switch that card back on. With wireless network, however, it's just the same as switching off the network card in the regular way, and if that works for you, you won't be looking for a $10 app to do the job in any case. Plus, of course, you can reverse this just by typing
sudo ifconfig en0 up
sudo ifconfig en1 up
I guess a solution would be to don't have sudo on your machine, and have a friend switch the network on and off via ssh, but it's not quite as smooth.
Next, I had a look at the terminal firewall, which seems a better choice. By typing
sudo ipfw add deny ip from any to any
you add a rule to the firewall which blocks all network traffic. To go back online, you can delete all rules by typing
sudo ipfw -q flush
By the way, this command also lets you back online when using Freedom, so I assume it operates by modifying the firewall rules as well. Also, note that if you have any existing firewall rules, the last command will remove them, though I guess a reboot would reset everything to the way it was.
While ipfw seems to be the tool of choice for this job, it won't work very well if you can just switch it off with a command which is actually simpler than the one to switch it on, so I wrote a little python script which will block communication on all ports for a set amount of time. Use it by typing
sudo python block.py 60
to block your internet access for 60 minutes, or change the number to whatever you want. The program is available here:
block.py
It works by calling ipfw to block communication as described above, then it spawns a subprocess which runs in the background and exits. The subprocess waits the prescribed amount of time, then restores communication.
At first, I thought perhaps it might be a little rude to write about this, as I guess it could potentially undermine the market for Freedom, which seems to be a one-man operation run in that one man's spare time. However I decided to go ahead anyway when I realised that the kind of people who pay $10 for an app that stops them from going online probably want a graphical interface. Also, according to the webpage, Freedom is used by hundreds of thousands of people (meaning the guy has made millons of dollars), and has been mentioned in a range of newspapers and popular webpages, including the Guardian and the New Yorker, so it seems to be doing quite well.
-Tor Nordam
Comments