如何连接到udp端口命令行?

这是我试过,但似乎不工作:

[root@ ~]# netstat -a|grep 48772 udp 0 0 *:48772 *:* [root@ ~]# telnet localhost 48772 Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused telnet: Unable to connect to remote host: Connection refused 

你可以使用netcat代替:

nc -u localhost 48772

您需要使用netcat,而telnet只支持tcp。 像这样的东西将工作:

 $ nc -u localhost 48772 

在大多数现代Linux机器上默认安装netcat(假设这是你所拥有的)。

也为了完整起见,我想指出,还有另一个工具叫做socat ,它把自己描述为“netcat ++”。 可能是一件好事,检查出来。 但是一般来说netcat会做你所需要的。

另一个select是使用socat :

 $ socat - UDP:localhost:48772 

它将其标准input连接到localhost上的端口48772。

相反,要设置侦听输出到标准输出的UDP端口48772的服务器:

 $ socat UDP-RECV:48772 STDOUT 

如果端口低于1024,则需要以root身份运行侦听器或使用sudo 。 socat可以充当接力器(实际上是它的主要目的),接受一个端口的input并输出到另一个端口。 绝对netcat ++