Untitled
unknown
python
4 years ago
2.0 kB
11
Indexable
from twisted.internet import protocol, reactor
from twisted.internet import ssl as twisted_ssl
import dns.resolver
import netifaces as ni
import time
connected = 0
DST_IP = "10.126.205.18"
DST_PORT = 14721
LISTEN_PORT = 6512
class BridgeProtocol(protocol.Protocol):
def connectionMade(self):
print time.strftime("%Y-%m-%d %H:%M")
print("Bridge client successfully connected")
self.factory.clients.append(self)
print "Current bridge client total: ", len(self.factory.clients)
# Proxy receive data from Bridge, directly send it to Rintis
def dataReceived(self, data):
print time.strftime("%Y-%m-%d %H:%M")
print("Bridge => Rintis")
print(data)
print(self.factory.rintis)
self.factory.rintis.write(data) # wip
# Called by RintisProtocol to directly send message to all Bridge Client
def write(self, data):
print time.strftime("%Y-%m-%d %H:%M")
print "Current bridge client total: ", len(self.factory.clients)
for c in self.factory.clients:
c.message(data)
def message(self, data):
self.transport.write(data)
class RintisProtocol(protocol.Protocol):
def connectionMade(self):
print time.strftime("%Y-%m-%d %H:%M")
print("Rintis successfully connected")
# Proxy receive data from Rintis, directly send it to Bridge
def dataReceived(self,data):
print time.strftime("%Y-%m-%d %H:%M")
print("Rintis => Bridge")
print(data)
self.bridge.protocol.write(data) # wip
# Called by BridgeProtocol to directly send message to Rintis
def write(self, data):s
print time.strftime("%Y-%m-%d %H:%M")
self.transport.write(data)
bridgeFactory = protocol.ServerFactory()
bridgeFactory.protocol = BridgeProtocol
bridgeFactory.clients = []
rintisFactory = protocol.ClientFactory()
rintisFactory.protocol = RintisProtocol
reactor.connectTCP(DST_IP, DST_PORT, rintisFactory)
reactor.listenTCP(LISTEN_PORT, bridgeFactory)
bridgeFactory.rintis = rintisFactory
rintisFactory.bridge = bridgeFactory
reactor.run()Editor is loading...