Using netcat to send a UDP packet without binding

喜欢而已 提交于 2019-12-05 05:08:44

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.

I do not believe you can use netcat in that way. I would recommend writing a simple Python script that does both the sending and receiving tasks in one process. That way you can hold that port exclusively and still accomplish both tasks.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!