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

时间:2023-02-03 09:06:06

I need to listen some arbitrary port inside the Linux embedded box. I chose port 6660 because it is meant for uncrypted connections anyway and since the Linux box running customized Linux OS there are not many ports open. I found out that netcat (nc on command line) would be the easiest and the best ready to go solution for that, so I do not have to start programming some C program for that purpose.

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

I managed to grasp the command and options and I implemented simplest way to listen plain text on my PC from another PC like this:

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

sven@sven:~$ nc 192.168.4.110 6660
sven@sven:~$ hello there!
anotherUser@userg:~$ nc -l -p 6660
anotherUser@userg:~$ hello there!

But the case is that the netcat tool is coming with the busybox package on that Linux box. And I am not sure what would be the syntax how to listen a port (6660 for example). I always get the same dialog:

但是案例是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

Also I've tried many other ways how to implement listening but cant get it done. I assume at least it would give me any options? also

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

nc -h

or

要么

nc --help

dont give any "minus" options

不要给任何“减号”选项

But sending the text from Linux embedded box to my PC works:

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

~ # nc 192.168.4.130 6660
fsdf
tere
^C
~ #
sven@sven:~$ nc -l -p 6660
fsdf
tere

Linux embedded box has fully functional net connection inside the same local network and has existing eth0 and lo links

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)

Töövõite!

Töövõite!

1 个解决方案

#1


12  

Here's the manual page for busybox's nc implementation.

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

The correct syntax is

正确的语法是

nc -l -p <port>

The issue is, I think, that your version of busybox is compiled without nc listening capabilities. Indeed there's a config option at build time, NC_SERVER, that needs to be enabled to turn that feature on.

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

Can you build another nc, perhaps from this version, and copy the binary onto your embedded host? You may need to build a cross-compiler environment.

您是否可以从此版本构建另一个nc,并将二进制文件复制到嵌入式主机上?您可能需要构建交叉编译器环境。

#1


12  

Here's the manual page for busybox's nc implementation.

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

The correct syntax is

正确的语法是

nc -l -p <port>

The issue is, I think, that your version of busybox is compiled without nc listening capabilities. Indeed there's a config option at build time, NC_SERVER, that needs to be enabled to turn that feature on.

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

Can you build another nc, perhaps from this version, and copy the binary onto your embedded host? You may need to build a cross-compiler environment.

您是否可以从此版本构建另一个nc,并将二进制文件复制到嵌入式主机上?您可能需要构建交叉编译器环境。