Linux – How to wait for a response on the inbound side of the socket using NC command under BusyBox

busyboxlinuxnetcat

I am having problems using the Netcat that comes with BusyBox 1.1.3 to make an HTTP request and then receive the response. The NC command seems to quit out as soon as it reaches the end of the request file I am sending. The -w option seems to be designed for this case, but looking at the source code, it does not seem possible that the -w option can have any effect on the receiving behavior.

The source code for this version NC on BusyBox is here…

http://git.busybox.net/busybox/tree/networking/nc.c?id=5cbe2519d8776bc15e0bc4dc7aeb6adc53e50b81

What am I doing wrong? Is there any way to send a file to a server via this version of NC and then wait to receive a response? Any creative ideas for other possible ways to do this in a script?

Note that this is an embedded system and I do not have the ability to upgrade the BusyBox version or upload new executable- I can only use script files and the BusyBox executable already available. Also note that there is no WGET available on the system.

Thanks!

-josh

Best Answer

Try this:

(echo "GET / HTTP/1.0"; sleep 1) | nc HOST 80
Related Question