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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9702447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:10:51  来源:igfitidea点击:

Using BusyBox version of netcat for listening tcp port

linuxlistenerportnetcatbusybox

提问by arapEST

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 上在我的 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!

采纳答案by jmtd

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

这是busybox nc implementation 的手册页

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这个版本构建另一个,并将二进制文件复制到您的嵌入式主机上?您可能需要构建一个交叉编译器环境。