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.

3
  • Would love to see that integrated with a Pomorodo technique tool ! Commented Oct 18, 2010 at 14:49
  • What platform do you want to do this on? Commented Oct 18, 2010 at 14:54
  • 1
    Unix/Linux-type (I have Mac OS X myself). If there was a solution that was automatically cross-platform for Windows, that would be neat, though. Commented Oct 18, 2010 at 15:03

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.