我正在创建一个拦截,解密,打印并将数据包发送到其原始目的地的代理,但是,我有一个两难的境地。我执行clienttoserver
就好了,但我需要启动{{ 1}},但是以非阻塞的方式。
似乎没有关于如何做这样的事情的资源,答案或示例,并且由于我不能,脚本失败,因为它需要接收客户端数据包,然后是服务器数据包,而不仅仅是服务器数据包它想做。
注意: 我可以 NOT 使用线程,因为它们需要传递数据并同时执行。
代码段:
servertoclient
- 我的启动脚本;
class clienttoserver:
def __init__(self):
self.ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.ss.connect(("place.server.end",1234))
key = "<key>"
self.cts = rc4.new(key)
skip = 'a'*len(key)
self.cts.encrypt(skip)
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.bind(('',1234))
self.s.listen(500)
self.client, self.addr = self.s.accept()
def main(self):
stcc = servertoclient()
stcc.main(self.ss)
while True:
pack = self.client.recv(1500)
decpack = self.cts.decrypt(pack[7:])
print "Packet from Client"
msgid = struct.unpack(">H",decpack[0:2])
print "Msg ID: ",msgid
print "Payload Len: ",decpack[2:4].encode("hex")
print "Payload: ",decpack[7:]
print ""
self.ss.send(pack)
class servertoclient:
def __init__(self):
key = "<key>"
self.stc = rc4.new(key)
skip = 'a'*len(key)
self.stc.encrypt(skip)
def main(self, ss):
while True:
pack = ss.recv(1500)
decpack = self.stc.decrypt(pack[7:])
print "Packet from Server:"
msgid = struct.unpack(">H",decpack[0:2])
print "Msg ID: ",msgid
print "Payload Len: ",decpack[2:5].encode("hex")
print "Payload: ",decpack[7:]
print ""
self.client.send(pack)