Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set source port when sending udp message with echo?

I'm using

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

in a bash script to test udp communication with a device. The device then returns the message. I've seen via wireshark that my source port is always changing.

Anyway, I want to set the source port, can I do that?

like image 621
Invader Zim Avatar asked Oct 19 '25 04:10

Invader Zim


1 Answers

Use netcat nc and its -p option to set the source port.

As said in the netcat man page

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

Then use it like this:

echo "This is my data"  | nc -u -p 50000 192.168.0.92 7291
like image 97
oliv Avatar answered Oct 20 '25 23:10

oliv