使用回显发送udp消息时设置源端口?

Set source port when sending udp message with echo?

我正在使用

echo "This is my data" > /dev/udp/192.168.0.92/7891

在 bash 脚本中测试与设备的 udp 通信。然后设备 returns 消息。我通过 wireshark 看到我的源端口总是在变化。

无论如何,我想设置源端口,我可以这样做吗?

使用 netcat nc 及其 -p 选项设置源端口。

如 netcat 手册页所述

-p source_port
Specify the source port nc should use, subject to privilege restrictions and availability.

然后像这样使用它:

echo "This is my data"  | nc -u -p 50000 192.168.0.92 7291