views:

64

answers:

1

Small apps like Freedom and Anti-social have created quite a stir lately. They cut you off from the internet either entirely or just block social networking sites in order to discourage procrastination and help you exert self control when you really want to get some work done.

I looked at the available options and also at some Google Chrome extensions and decided that none of them is exactly doing what I want, so I'm planning to write my own little Python tool to do that. My first impulse was to simply modify /etc/hosts to re-route requests to certain servers back to localhost. However, this can only block entire domains. I'd need to block addresses based on regular expressions or simple string matching to block something like google.com/reader (yes, this one in particular), but not the entire google.com domain.

Which Python framework can I use to monitor my network traffic and block blacklisted addresses and what is the basic design to achieve what I want to do? Do I use the socket library? I'm very comfortable with Python, but I'm very new to network programming.

+2  A: 

Since you're comfortable with python, I'd directly recommend twisted. It is slightly harder than some other libraries, but it is well-tested, has great performance and many features. You would just implement a small HTTP proxy and do your regexp filtering on the URLs.

knitti
If I do this through a proxy, don't I always have to connect through that proxy? It also shouldn't be too easy to bypass by simply disabling the proxy.
oceanhug
well, if you connect to a process which itself is then connecting to the real server, that's a proxy by definition. Easy or not, you should define what you want. For every problem to solve there is a bit of domain knowledge necessary, how would you try to solve the problem if not by proxy?
knitti