[BusyBox] Scriptable telnet?

Rob Landley rob at landley.net
Mon Jan 12 19:41:00 UTC 2004


On Monday 12 January 2004 07:18, Paul Fox wrote:

> i seem to recall solving a similar problem with something that looked
> a lot like:
>   (echo -en 'ls\r\0'; sleep 2) | nc <host> <port>
> or somesuch.  cheap, dirty, and not guaranteed to work.  but it can
> get you where you need to be when all you have are stock binaries.
> e.g., on my current development machine this works:
>   echo 'GET /index.html'| nc www 80
> but this doesn't:
>   echo 'GET /index.html' | telnet www 80
> and this fixes it:
>   (echo 'GET /index.html'; sleep 2) | nc www 80

The same problem: nc exits when stdin closes, without waiting for the network 
connection to close.

The netcat.c I posted yesterday actually works correctly by using the 
"shutdown" syscall (try "man 2 shutdown") on each end of the connection 
independently.  That way if stdin hits EOF but the other side takes 30 
seconds to get back to you with its result, it still does the right thing.

If my darn cold gets any better today I may try hacking the right thing into 
busybox's netcat.  It's not too hard...

Rob




More information about the busybox mailing list