本文介绍了Python TCP堆栈实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个实现独立TCP堆栈的python库?

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

我无法使用通常的python套接字库,因为我正在通过套接字接收数据包流(它们正在通过此套接字传送给我).当我收到发送到特定端口的TCP SYN数据包时,我想接受连接(发送一个syn-ack),然后获取另一端发送的数据(适当的确认).

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).

我希望已经编写了某种可以利用的TCP堆栈.有任何想法吗?过去,我曾在C项目中使用过lwip -在python中遵循这些原则是很完美的.

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.

推荐答案

您没有说您正在使用哪个平台,但是如果您正在使用linux,我会打开调整/点击接口并获取IP数据包作为真正的网络接口进入内核,因此内核可以完成所有棘手的TCP任务.

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.

(例如) OpenVPN 的工作方式-它接收原始IP数据包UDP或TCP,然后通过tun/tap接口将它们通过隧道传输回内核.

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.

我认为现在Windows也有一个tun/tap接口,它是为Windows的OpenVPN端口开发的.

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

这篇关于Python TCP堆栈实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:42
查看更多