combine netcat with chat on bash for automatic udp responses
I want to combine "chat" and "nc" on linux, so I will create a tiny udp server that responds on a specific request and sends back an answer.
In fact I want to redirect the stdout of "nc"开发者_运维百科 to the stdin of "chat" and vice versa. My first attempt was:
nc -w 3000 -u -n -l -p 30000 >&1111 <2222 &
chat -V 'request' 'answer' >&2222 <1111
But it didn't work.
use socat instead of netcat. Something like this :
socat UDP-LISTEN:5555 EXEC:"chat -sv ping pong",pty
To test it, you can open another terminal, and use socat to bridge stdio and an UDP socket :
socat - UDP:localhost:5555
Type ping, and you will get pong !
精彩评论