combine netcat with chat on bash for automatic udp responses

前提是你 提交于 2019-12-24 03:08:26

问题


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.


回答1:


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 !



来源:https://stackoverflow.com/questions/5284852/combine-netcat-with-chat-on-bash-for-automatic-udp-responses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!