带有 netcat 或 socat 的回显服务器

Moh*_*ati 25 netcat echoserver socat

我想要一个 UDP 回显服务器来获取数据包,并准确地回复它收到的内容。我怎样才能简单地使用netcator做到这一点socat?它应该永远保持活动状态并处理来自多个主机的数据包。

Mat*_*erg 21

Another netcat-like tool is the nmap version, ncat, that has lots of built in goodies to simplify things like this. This would work:

ncat -e /bin/cat -k -u -l 1235
Run Code Online (Sandbox Code Playgroud)

-e means it executes /bin/cat (to echo back what you type)
-k means keep-alive, that it keeps listening after each connection
-u means udp
-l 1235 means that it listens on port 1235


Moh*_*ati 15

我曾经socat -v PIPE udp-recvfrom:5553,fork运行服务器和socat - udp:localhost:5553客户端。 是一个很大的帮助!

  • 来自 http://stackoverflow.com/a/35857095/222529 的替代方法是 `socat TCP4-LISTEN:2000,fork EXEC:cat` (4认同)

小智 7

您还可以使用 socat(而不是使用 netcat)作为回显服务器,使用 netcat 作为客户端。

Socat 回显服务器(侦听 TCP 端口 1234):

socat -v tcp-l:1234,fork exec:'/bin/cat'
Run Code Online (Sandbox Code Playgroud)

Netcat 客户端(在 TCP 端口 1234 上连接到 serverip):

nc serverip 1234
Run Code Online (Sandbox Code Playgroud)