通过我的程序路由所有数据包?

发布于 2024-12-25 17:52:31 字数 228 浏览 6 评论 0原文

我想构建一个通过我的应用程序路由所有网络流量(不仅仅是 HTTP)的应用程序。基本上,我想要的是给予我的应用程序的所有流量(它们永远不应该到达实际目标,我的应用程序应该处理这个),然后将其转发到服务器;输入也是如此,只是相反(服务器 -> 应用程序 -> 想要答案的程序)。是否有任何库(或类似的东西)可以使创建应用程序变得更容易?我正在寻找可以从 Python 或 Java 中使用的东西,但如果确实需要,我可以学习另一种语言。

I want to build an application that routes all network traffic (not just HTTP) through my application. Basically, what I want is all the traffic to be given to my application (they should never reach the actual target, my application should handle this), which will in turn be forwarded to a server; same goes for input, just reversed (server -> application -> program which wants an answer). Are there any libraries (or similar stuff) that would make creating the application easier? I'm looking for something that I can use from Python or Java, but if it's really needed, I can learn another language.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谈情不如逗狗 2025-01-01 17:52:31

你想要使用的是一个数据包捕获库,你可以使用pcap或其实现或绑定在 python 或 java 中。

然而,像这样的事情通常是在底层实现的,最好使用 C,
这是一个教程 教程

编辑:根据您的评论,您绝对想看看 netfilter hooks

当你在看它时,你可能还想看看 netfilter 钩子

What you want to use is a packet capture library, you can use pcap or its implementation or bindings in python or java.

However things like these are ussually implemented at the low level ideally using C,
Here is a tutorial Tutorial

EDIT: In light of your comments you definitely want to take a look at netfilter hooks

While you are at it you also might want to take a look at netfilter hooks

梦途 2025-01-01 17:52:31

看看 Jpcap

Have a look at Jpcap.

硪扪都還晓 2025-01-01 17:52:31

如果您只想路由 TCP 流量,那么使用线程和套接字实际上很简单。
您应该为您想要访问的每个服务器监听不同的端口。无论是在Java还是Python中,你都必须为你想要监听的每个端口创建一个“套接字”。

对于每个新连接,你创建一个到服务器的新连接,并创建两个新线程来处理该连接,一个线程将读取所有内容从客户端发送到服务器。另一个将从服务器读取所有内容并将其发送到客户端。当连接的任何一端关闭它时,您将关闭另一端并结束两个线程。

If you want to route only tcp traffic is actually kind of simple using threads and sockets.
You should listen in a different port for every server you want to reach. Either in Java or Python you have to create a "socket" for every port you want to listen in.

For every new connection you create a new connection to the server and create two new threads to handle that connection, one thread will be reading everything from the client and sending it to the server. The other will be reading everything from the server and sending it to the client. When any end of the connection closes it, you close the other and end both threads.

给妤﹃绝世温柔 2025-01-01 17:52:31

如果您在 Linux 上执行此操作,则应考虑使用 TUN/TAP 设备,这是一个非常方便的工具,用于拦截网络流量以进行自定义处理。如果您不熟悉,这里有一个基本教程 http://backreference.org/2010 /03/26/tuntap-interface-tutorial/

If you're doing this on Linux, you should consider using a TUN/TAP device, which is a very handy tool for intercepting network traffic for custom processing. Here's a basic tutorial if you're unfamiliar http://backreference.org/2010/03/26/tuntap-interface-tutorial/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文