Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using BusyBox version of netcat for listening tcp port

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.

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:

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:

~ # 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:

~ # 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

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!

like image 344
arapEST Avatar asked Mar 14 '12 12:03

arapEST


1 Answers

Here's the manual page for busybox's 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.

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.

like image 197
jmtd Avatar answered Sep 21 '22 07:09

jmtd