使用netcat发送UDP包不绑定 [英] Using netcat to send a UDP packet without binding
问题描述
我正在尝试使用 netcat 来模拟 NAT 穿越协议.
我有一个实例正在侦听端口 6666 上的 UDP 数据包,如下所示:
nc -ul 6666
在另一个终端窗口中,我尝试定期从端口 6666 发送一个 UDP 数据包(以打开路由器上的返回路径.这将在脚本中每 20 秒重复一次以重新打开端口)>
nc -u -p6666 mypinghost.com 4444
问题是 netcat 在此 ping 调用中失败并显示以下消息:
nc:绑定失败:地址已被使用
这意味着绑定到端口 6666 的侦听器正在阻止另一个进程从该端口发送,或者可能是 netcat 试图绑定到 6666 以进行侦听.
netcat 就是这样写的,或者我可以用某种方式让我发送数据包而不绑定到端口来监听吗?
nc -ul 6666
在 UDP 端口 6666 上侦听.
<块引用>nc -u -p6666 mypinghost.com 4444
使用UDP 6666端口作为源端口,发送到mypinghost:4444.
<块引用>nc:绑定失败:地址已被使用
那将是第二次 netcat
调用,其中 6666 已被第一个调用使用.
这意味着绑定到端口 6666 的侦听器正在阻止另一个进程从该端口发送
正确.
<块引用>或者可能是 netcat 试图绑定到 6666 来监听.
而且绝对.你告诉它这样做,它就这样做了.
您尝试在同一主机中的两个进程之间执行的操作是不可能的.一次只有一个进程可以使用特定的本地 UDP 端口,除非您使用 SO_REUSEADDRESS
,而 netcat
似乎没有实现.
正如另一位发帖人所建议的,解决方案在于使用单个进程.
I am trying to use netcat to simulate a NAT traversal protocol.
I have one instance that is listening for UDP packets on port 6666, as so:
nc -ul 6666
In another terminal window, I am trying to periodically send a UDP packet from port 6666 (to open the return path on my router. this would be in a script that repeats every 20 seconds to re-open the port)
nc -u -p6666 mypinghost.com 4444
The problem is netcat fails on this ping call with the message:
nc: bind failed: Address already in use
Which implies that the listener having bound to port 6666 is blocking another process from sending from that port, or possibly that netcat is trying to bind to 6666 to listen.
Is this just how netcat is written, or can I tickle it some way to let me send a packet without binding to the port to listen?
nc -ul 6666
Listen at UDP port 6666.
nc -u -p6666 mypinghost.com 4444
Using UDP port 6666 as the source port, send to mypinghost:4444.
nc: bind failed: Address already in use
That would be on the second netcat
invocation, where 6666 is already in use by the first one.
Which implies that the listener having bound to port 6666 is blocking another process from sending from that port
Correct.
or possibly that netcat is trying to bind to 6666 to listen.
And definitely that. You told it to do that, so it did it.
What you are trying to do is impossible between two processes in the same host. Only one process can use a specific local UDP port at a time, unless you use SO_REUSEADDRESS
, which netcat
doesn't appear to implement.
As the other poster has suggested, the solution lies in using a single process.
这篇关于使用netcat发送UDP包不绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!