block a network port

Tim Williams tim at tdw.net
Wed Aug 30 11:31:41 EDT 2006


On 29 Aug 2006 20:43:49 -0700, alex23 <wuwei23 at gmail.com> wrote:
> abcd wrote:
> > ok, no of any python solutions?  or command-line firewalls?
>
> You did try searching Google for "python firewall", right?
>
> http://www.google.com.au/search?q=python+firewall
>
> The very first entry is a pointer to a solution for Windows.

That first entry was my thread :)

IPFW is stable and runs as a Windows service,  the rules can be
added/deleted/changed/viewed in real-time making it a good candidate
for pairing with Python.

I have used it to write servers that temporarily firewall themselves
against dubious connections.

My preferred method is something like

def ip_fw(fwcmd): #
        try:
            i,o,e = win32pipe.popen3('C:\\ipfw\\bin\\ipfw '+fwcmd)
            return i,o,e
        except:
            print sys.exc_info()[0]

Nowadays I might use something other than popen3 depending on the
level of return status I needed.

(from memory, not tested, and not the best Python code )

HTH :)



More information about the Python-list mailing list