我需要在Linux嵌入式框中監聽一些任意的端口。 我選擇了端口6660,因爲它無論如何都是用於未加密的連接,並且由於運行定製Linux操作系統的Linux機器沒有很多端口打開。 我發現netcat(命令行上的nc)將是最簡單和最好的解決方案,因此我不必爲此目的開始編寫一些C程序。使用BusyBox版本的netcat監聽tcp端口
我設法掌握命令和選項和我實現了最簡單的方式來聽我的PC上的另一臺電腦這樣的純文本:
[email protected]:~$ nc 192.168.4.110 6660
[email protected]:~$ hello there!
[email protected]:~$ nc -l -p 6660
[email protected]:~$ hello there!
但情況是netcat的工具與busybox的未來打包在該Linux機器上。我不確定如何監聽端口的語法(例如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
而且我已經試過許多其他方式如何實現監聽,但不能把它做完。 我認爲至少它會給我任何選擇?也
nc -h
或
nc --help
不給任何 「減」 選項
但發送從嵌入式Linux框中的文本到我的電腦的工作原理:
~ # nc 192.168.4.130 6660
fsdf
tere
^C
~ #
[email protected]:~$ nc -l -p 6660
fsdf
tere
嵌入式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!