Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python TCP stack implementation

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

I can't use the usual python socket library because I'm receiving a stream of packets over a socket (they are being tunneled to me over this socket). When I receive a TCP SYN packet addressed to a particular port, I'd like to accept the connection (send a syn-ack) and then get the data sent by the other end (ack'ing appropriately).

I was hoping there was some sort of TCP stack already written which I could utilize. Any ideas? I've used lwip in the past for a C project -- something along those lines in python would be perfect.

like image 586
David Underhill Avatar asked Oct 17 '09 00:10

David Underhill


2 Answers

You don't say which platform you are working on, but if you are working on linux, I'd open a tun/tap interface and get the IP packets back into the kernel as a real network interface so the kernel can do all that tricky TCP stuff.

This is how (for example) OpenVPN works - it receives the raw IP packets over UDP or TCP and tunnels them back into the kernel over a tun/tap interface.

I think that there is a tun/tap interface for windows too now which was developed for the OpenVPN port to windows.

like image 72
Nick Craig-Wood Avatar answered Nov 08 '22 04:11

Nick Craig-Wood


Glancing over Scapy, it looks like it might be able to handle these low-level situations. I haven't used it myself so I can't confirm that it does what you've explained; I've only glanced over the documentation.

like image 2
Mark Rushakoff Avatar answered Nov 08 '22 05:11

Mark Rushakoff