Python TCP Stack Implementation

Is there a python library that implements a standalone TCP stack?

I cannot use the usual python socket library, because I get a packet stream through the socket (they are tunneling to me on this socket). When I receive a TCP SYN packet addressed to a specific port, I would like to accept the connection (send syn-ack) and then receive the data sent by the other end (respectively).

I was hoping some kind of TCP stack was already written that I could use. Any ideas? I used lwip in the past for a C project - something along these lines in python would be ideal.

+7
python network-programming network-protocols tcp raw-sockets
source share
5 answers

You do not say what platform you are working on, but if you are working on linux, I would open the tun / tap interface and return the IP packets to the kernel as a real network interface so that the kernel can do all these complex TCP things .

Here's how (for example) OpenVPN works โ€” it receives raw IP packets through UDP or TCP and tunnels them back to the kernel through the tun / tap interface.

I think there is now a tun / tap interface for windows that was designed for the OpenVPN port for windows.

+7
source share

A look at Scapy , it looks like he can handle these low-level situations. I did not use it myself, so I canโ€™t confirm that it does what you explained; I just looked through the documentation.

+2
source share

I know this is not directly related to Python, but if you want to do heavy network processing, you should consider Erlang instead of Python. Just a suggestion really ... you can always take a picture by using Twisted ... if you feel adventurous (and you have a lot of time on your side); -)

+1
source share

Perhaps you can use the ctypes module to import lwip and reuse it.

0
source share

If you are already tied to software on the other end of the socket that sends you TCP packets, TCPWatch will probably show you how to get to the SYN packets. SCAPY is certainly great for sending exactly the packages you want, but I'm not sure that it will work as a proxy.

http://hathawaymix.org/Software/TCPWatch

However, if you are not committed to what is being sent, try using Twisted Conch or Paramiko to forward SSH. Even if you don't need encryption, you can still use them with blowfish, which has a small effect on your processor. This does not mean that you need Conch on the other end, since SSH is standardized, so any SSH software should work. In the SSH world, this is commonly referred to as โ€œport forwarding,โ€ and people use the SSH terminal client to log into the SSH server and configure the port forwarding tunnel. Conch and Paramiko allow you to create this in a Python application so that the SSH terminal client does not need.

0
source share

All Articles