开发者

combine netcat with chat on bash for automatic udp responses

开发者 https://www.devze.com 2023-02-16 16:20 出处:网络
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.

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 !

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号