-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTwisted_proxy.py
More file actions
52 lines (39 loc) · 1.34 KB
/
Twisted_proxy.py
File metadata and controls
52 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from twisted.internet import protocol, reactor
from twisted.protocols import basic
class proxy_ServerProtocol(protocol.Protocol):
def __init__(self):
self.buffer = None
self.client = None
def connectionMade(self):
factory = protocol.ClientFactory()
factory.protocol = proxy_ClientProtocol
factory.server = self
reactor.connectTCP('ec2-54-89-126-237.compute-1.amazonaws.com',6675, factory)
def dataReceived(self, data):
if (self.client != None):
self.client.write(data)
else:
self.buffer = data
def write(self, data):
self.transport.write(data)
print 'Server: ' + data.encode('hex')
class proxy_ClientProtocol(protocol.Protocol):
def connectionMade(self):
self.factory.server.client = self
self.write(self.factory.server.buffer)
self.factory.server.buffer = ''
def dataReceived(self, data):
self.factory.server.write(data)
def write(self, data):
self.transport.write(data)
print 'Client: ' + data.encode('hex')
def main():
import sys
from twisted.python import log
log.startLogging(sys.stdout)
factory = protocol.ServerFactory()
factory.protocol = proxy_ServerProtocol
reactor.listenTCP(6666, factory)
reactor.run()
if __name__ == '__main__':
main()