使用BusyBox版本的netcat来监听tcp端口

ara*_*EST 10 linux port listener netcat busybox

我需要在Linux嵌入式盒子里面听一些任意的端口.我选择了端口6660,因为它无论如何都是用于未加密的连接,并且由于运行自定义Linux操作系统的Linux机箱没有很多端口打开.我发现netcat(命令行上的nc)将是最容易和最好的解决方案,所以我不必为此目的开始编写一些C程序.

我设法掌握了命令和选项,我实现了最简单的方法来从另一台PC上在我的电脑上听取纯文本,如下所示:

sven@sven:~$ nc 192.168.4.110 6660
sven@sven:~$ hello there!
anotherUser@userg:~$ nc -l -p 6660
anotherUser@userg:~$ hello there!
Run Code Online (Sandbox Code Playgroud)

但是案例是netcat工具随Linux盒子上的busybox包一起出现.而且我不确定如何监听端口的语法(例如6660).我总是得到相同的对话框:

~ # nc -l -p 6660
BusyBox v1.17.1 (Debian 1:1.17.1-8) multi-call binary.
Usage: nc [IPADDR PORT]    
Open a pipe to IP:PORT
Run Code Online (Sandbox Code Playgroud)

此外,我还尝试了许多其他方法来实现听力,但无法完成.我假设至少会给我任何选择吗?也

nc -h
Run Code Online (Sandbox Code Playgroud)

要么

nc --help
Run Code Online (Sandbox Code Playgroud)

不要给任何"减号"选项

但是将文本从Linux嵌入式盒子发送到我的PC可以工作:

~ # nc 192.168.4.130 6660
fsdf
tere
^C
~ #
sven@sven:~$ nc -l -p 6660
fsdf
tere
Run Code Online (Sandbox Code Playgroud)

Linux嵌入式盒子在同一本地网络内部具有全功能网络连接,并且具有现有的eth0和lo链接

eth0      Link encap:Ethernet  HWaddr D0:E3:47:00:03:5F  
          inet addr:192.168.4.179  Bcast:192.168.4.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28046281 errors:0 dropped:0 overruns:0 frame:0
          TX packets:428464 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2458890234 (2.2 GiB)  TX bytes:83021395 (79.1 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2282 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2282 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:444956 (434.5 KiB)  TX bytes:444956 (434.5 KiB)
Run Code Online (Sandbox Code Playgroud)

Töövõite!

jmt*_*mtd 14

这是busybox的nc实现的手册页.

正确的语法是

nc -l -p <port>
Run Code Online (Sandbox Code Playgroud)

我认为问题是你的busybox版本是在没有nc监听功能的情况下编译的.确实在构建时有一个配置选项NC_SERVER,需要启用它才能打开该功能.

你可以nc这个版本构建另一个,并将二进制文件复制到你的嵌入式主机上吗?您可能需要构建交叉编译器环境.