Portforwarding using Twisted, Python

This is a very short proxy written in Python using Twisted 1.3. It forwards port 1080 to localhost:80.

from twisted.internet import reactor
from twisted.protocols import portforward

def server_dataReceived(self, data):
    print 'Server received data:', data
    portforward.Proxy.dataReceived(self, data)
portforward.ProxyServer.dataReceived = server_dataReceived

def client_dataReceived(self, data):
    print 'Client received data:', data
    portforward.Proxy.dataReceived(self, data)
portforward.ProxyClient.dataReceived = client_dataReceived

reactor.listenTCP(1080, portforward.ProxyFactory('localhost', 80))
reactor.run()

Short and sweet, I think.

mike

Hello,

This is the best example that I have found on the net. Thank You for the share,I have been saved from a lot of trial and error(twisted.protocols.portforward has little docs for beginners ) ..

Cheers.

Leave a comment