将 UDP 数据包转发到保持原始源地址的多个 IP
我有一个工作系统,通过发送到固定 IP:端口的 UDP 数据包接收数据,我想使用一个程序(某种代理?)将这些数据包的副本发送到新的 IP:端口(或一系列IP:端口,但都在与程序相同的 LAN 内)。
并不像看起来那么容易,因为我需要复制的数据包具有与原始数据包相同的源 IP 地址。
在我的研究中,我发现 PCap.Net(WinPCap .NET 包装器)很有用,因为它可以从头开始构建数据包,并且支持修改所有地址字段。我已经设法捕获数据包并构建它们。但某种程度上他们并没有到达期望的目的地(!?)。我应该使用不同的 PacketCommunicator 来接收和发送它们吗?
无论如何,这个问题与 PCap.Net 并不完全相关,而是了解实现我的预期目标的替代方法。通过免费应用程序?商业应用?开源样本?还有其他库可以使用吗?
我的系统是基于 Windows 的(这里没有可用的 Linux)。我有 C# (.NET) 经验(如果 NET 绑定不可用,我无法使用 C++ 库)。
非常感谢您的帮助
I have a working system that receives data via UDP packets sent to a fixed IP:Port and I want to use a program (some kind of proxy?) to send a copy of those packets to a new IP:Port (or a list of IP:Ports, but all inside the same LAN as the program).
Not as easy as it seems, because I need the copied packets to have the same Source IP address as the original ones.
In my research, I have found PCap.Net (WinPCap .NET wrapper) to be useful, because it can build a Packet from scratch and it supports modifying all the address fields. I have managed to capture the packets and build them. But somewhat they are not arriving at the desired destination (!?). Should I use a different PacketCommunicator to receive and send them?
Anyway, the question is not fully related to PCap.Net but to know alternative ways to achieve my desired goal. Via a free application? commercial application? Open source sample? Any other library to use?
My systems are Windows based (no Linux available here). And I have C# (.NET) experience (I can not use a C++ library, if NET bindings are not available).
Many thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道这是一个老问题,但这就是答案:
http://code.google.com/p /samplicator/
侦听 UDP 并将其转发到一个或多个其他 IP 地址,可以选择欺骗(原始)源 IP 地址。
用于转发netflow/sflow/syslog等数据包。
I know it's an old question, but this is the answer:
http://code.google.com/p/samplicator/
Listens for UDP and forwards it to one or more other IP addresses, optionally spoofing (the original) source IP address.
Used for forwarding netflow/sflow/syslog etc. packets.
你应该首先考虑网络。如果流量需要经过路由器,则可能无法实现。
原始数据包通过:
源->路由器->您的服务器
如果您尝试将其发回,如下所示:
您的服务器->路由器->另一台计算机
,那么路由器甚至可能不接受此流量,因为根据路由器配置,它不可能来自您的计算机。想想看 - 如果允许的话,我可以以任何人的身份发送流量。
但是,在 LAN 中这是非常可行的(除非您的交换机上有某种 MAC 欺骗保护)
you should think about network first. it may not be possible if traffic needs to go through router.
the original packet came through:
source->router->your server
if you are trying to sent it back out like so:
your server->router->another computer
then the router may not even accept this traffic, since it can not originate from your computer, according to routers configuration. just think about it - i could send traffic as anybody, if that was allowed.
however, in LAN that's very doable (unless you have some sort of MAC spoofing protection on your switches)
您正在尝试做的事情称为“UDP 转发”。您收到一个 UDP 数据包,然后将其转发到另一台主机
这是一个执行此操作的应用程序(似乎是免费的)
What you are trying to do is called "UDP Forwarding". You receive a UDP packet and then forward it to another host
Here is an application that does that (seems to be free)
除了保留源IP地址和更改目标IP地址之外
您必须交换源 MAC 地址和目标 MAC 地址。
如果您将原始数据包发送到路由器/交换机/调制解调器,但 MAC 地址不是它的地址。
它会被丢弃。
基本上,您必须修改您处理的每个网络层,并正确处理寻址。
抱歉我的拼写
in addition to keeping the source ip address and changing the destination ip address
you MUST swap the source and destination mac addresses.
if you send a raw packet out to your router/switch/modem, but the mac address is not addresses to it.
it will be dropped.
basicly, you have to revise every network layer your dealing with, and handle addressing approperately.
Sorry for my spelling
如果您尝试欺骗目标地址来执行网络流中继等操作,您通常会被中间的反欺骗路由器阻止。例如,我在使用 AWS 时就遇到过这种情况。
解决方案是获取原始 udp 数据包,然后将其发送到另一个 udp 数据包中的新目的地。当它到达目的地时,您必须“解包”数据包,然后在环回接口上将其发送给自身(本质上是“解包”)。
您可以使用带有套接字模块的 python 代码来完成此操作。
If you try to spoof the destination address to do things like netflow relaying you often will get blocked by anti-spoofing routers inbetween. I encountered this with AWS for example.
The solution is to take the RAW udp packet and then just send that along to your new destination inside another udp packet. When it reaches the destination you have to "unwrap" the packet and then send it to itself on the loopback interface (essentially "unwrapping").
You can do this with python code with the sockets module.