disabling TCP connections, just for one script

Adam Monsen haircut at gmail.com
Fri Sep 9 12:41:06 EDT 2005


It would be helpful to be able to temporarily disable AF_INET socket
connections (I don't care about IPv6 for now).

What I'd like to do is create an environment for a Python script that
appears like the network interface is down, so any remote socket stuff
should fail (like an HTTP GET request to Google's home page, for
example).

Anyone know an easy way to do that? Maybe by manipulating the socket
module or something? I'd still like to be able to access the internet
from other programs (like my Web browser, IM app, etc.) while I'm
working on this script, so unplugging the network cable or just
temporarily shutting down networking for the whole system aren't really
acceptable solutions.

Maybe chroot would be useful, but this seems a little complicated for
what I'm trying to do. Setting up some kind of Xen or UML (user mode
Linux) environment, and just disabling networking within that virtual
machine would possibly work, too.

--
Adam Monsen
http://adammonsen.com/




More information about the Python-list mailing list