How to send only one UDP packet with netcat?

后端 未结 5 1843
挽巷
挽巷 2021-01-29 19:20

I want to send only one short value in a UDP packet, but running the command

echo -n \"hello\" | nc -4u localhost 8000

I can see that the serve

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-29 19:52

    If you are using bash, you might as well write

    echo -n "hello" >/dev/udp/localhost/8000
    

    and avoid all the idiosyncrasies and incompatibilities of netcat.

    This also works sending to other hosts, ex:

    echo -n "hello" >/dev/udp/remotehost/8000
    

    These are not "real" devices on the file system, but bash "special" aliases. There is additional information in the Bash Manual.

提交回复
热议问题