0

Any ideas why nc is not showing anything when ran on a busybox based container image? The problem appears when trying to connect to port on 127.0.0.1/localhost.

/app # nc -v 127.0.0.1 12345
/app # nc -v localhost 12345
/app # nc
BusyBox v1.35.0 (2022-08-01 15:14:44 UTC) multi-call binary.

Usage: nc [OPTIONS] HOST PORT  - connect
nc [OPTIONS] -l -p PORT [HOST] [PORT]  - listen
...

What I would expect is to see if nc has connected or not. On normal Ubuntu the command outputs successful or unsuccessful connections like below. On busybox I don't know what happened because nothing is outputted. enter image description here

4
  • What is running on port 12345? What sort of output do you expect to see?
    – larsks
    Sep 5, 2022 at 15:57
  • 2
    Many commands in busybox are a pale imitation of the full command/tool they mimic. So I'm not quite sure what you expected to see.
    – HBruijn
    Sep 5, 2022 at 15:58
  • @larsks I added explanation what I expect: basically I want to simply know if it connected or not?
    – nosalan
    Sep 6, 2022 at 8:26
  • It looks to me like busybox nc returns an error code if it fails to connect. So nc localhost 12345 || echo FAILED is maybe what you want.
    – larsks
    Sep 6, 2022 at 11:57

1 Answer 1

0

Most Linux/Unix programs don't saying anything unless some error occurred. This is because same programs are often also used for scripting. See https://en.wikipedia.org/wiki/Unix_philosophy Additionally BusyBox by design is quite and tries to avoid large texts.

But you can check for error code that the program returned with $? command.

$ busybox httpd -p 8080
$ busybox nc 127.0.0.1 8081
nc: can't connect to remote host (127.0.0.1): Connection refused
$ echo $?
1
$ busybox nc 127.0.0.1 8080
^C
$ echo $?
130

Here I started httpd on port 8080. Then executed the nc but it failed with error code 1. Again started nc on 8080 port and it was successful and didn't tell anything. But I interrupted it so the exit code was 130:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .