sockets - Python TCP Payload Duplication - Passing through data to multiple endpoints concurrently -
This is my first post here!
My goal is to duplicate the payload of a unidirectional TCP stream and send multiple payouts to this payload concurrently. I have a working prototype written in Python, although I'm new to Python, and for socket programming. Ideally the solution is capable of running in both Windows and * Nix environments.
This prototype works, however it creates a new sending TCP connection for each buffer length (currently set to 4096 bytes). The main problem with this is that I will eventually send from local ports, and ideally I want to pass data from each single incoming TCP stream to each single TCP stream (for each end point). The incoming data may vary from hundreds of megabytes to less than 1024 bytes.
Currently, a new outgoing TCP stream is started for each 4096 bytes. I'm not sure whether the problem is in its implementation of threading, or if something else is not really clear at all.
In my research, I have found that selection () can help, though I'm not sure it would be appropriate because I want to process some of the incoming data and send it for some cases in the future. The answer may be required.
Even though I have code (some code variations I have tried commented out):
#! / Usr / bin / python # import a TCP payload duplication import lead socket import threading * bufsize = 4096 host = '' # # ways: # endpoint DF message (endpoint, handles to send data port, data) : sendSocket = socket (AF_INET, SOCK_STREAM) # sendSocket.setblocking (1) sendSocket.setsockopt (SOL_SOCKET, SO_REUSEADDR, 1) #sendport = sendSocket.getsockname #print try Sendport: sendSocket.connect ((endpoint, port)) sendSocket. Sendall (Data) Except IOError: Send "Send" failed. Error code: "+ str (msg [0]) + 'Message:' + Mess [1] sys.exit () #ndpoint Araf forward (service, Iandeepioaiantielti, port, data) to send Start threading: # endpoint send a new message to the endpoint in Iandeepioaiantielaiti for each endpoint list thread: print "forwarding% to% s S Data:% s to% s:% s "% (service, host, port, endpoint, port) # off (endpoint, port, data) ethread = threading. Thread (target = send, args = (endpoint, port, data)) ethread.start () # Threading deef clientthread (conn, service, ENDPOINT_LIST, port) for incoming subscribers: While correct: #receive data form client data = Conn.recv (bufsize) data is not: break cthread = threading.Thread (target = forward, args = (service, ENDPOINT_LIST, port, data)) cthread.start () # No data? Connection Close Connkclose () listen socket for #handles incoming connections def (service, ENDPOINT_LIST, port): # socket listen socket listening socket socket (AF_INET, SOCK_STREAM) # Re: Allow address to use - I think it is important stops to prevent TCP streams never-ending local ports closing which listenSocket.setsockopt (SOL_SOCKET, SO_REUSEADDR, 1) attempting to bind a socket to cancel # HostTry and try: listenSocket.bind ((host, port)) # Display error message if you can not leave the IOError message: Print "Tie failed. Error code:" + str (msg [0]) + ' Message: 'msg [1] sys.exit () listen to socket listenSocket.listen (10) print "service% s on port% s listening"% (service, port), while true: # connections To accept conn, addr = listenSocket.accept () print 'connect' to each connection lthread = addr for threading [0] + ':' + str (addr [1]) + 'port' + str (port) ) #pr Initial thread Thread (target = Claintthred, Arges = (Con, Service, ENDPOINT_LIST, p Ort)) lthread.start () # ListenSocket.close (if it does not shut down a data connection) service = "DNB-one-way-TCP -Services-Name 1 "ENDPOINT_LIST = [" 192.168.1.100 "," 192.168.1.200 "] I have seen in other libraries trying to achieve my goal:
Scapy However, I would like to give them enough information for their general requirements and programming skills levelFound Till.
If someone approaches this approach, or in some other way, this goal can be achieved, please tell me! "Lesson">
In short, you have a question that there are not enough ports, right? It seems that you did not stop the socket after sending. Try it Send () : ... except for IOError msg: Send failed. Error code: "+ str (msg [0] ) + 'Message:' msg [1] sys.exit () Finally: sendSocket.close ()
Comments
Post a Comment