How to send only one UDP packet with netcat?

后端 未结 5 1846
挽巷
挽巷 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:53

    I did not find the -q1 option on my netcat. Instead I used the -w1 option. Below is the bash script I did to send an udp packet to any host and port:

    #!/bin/bash
    
    def_host=localhost
    def_port=43211
    
    HOST=${2:-$def_host}
    PORT=${3:-$def_port}
    
    echo -n "$1" | nc -4u -w1 $HOST $PORT
    

提交回复
热议问题