I've found this way of checking whether a host is accessible on a given port, however I am only interested in the status code of the command, therefore I am trying something like this:
[CptBartender@somewhere ~]$ <dev/tcp/host/port ; echo $?
0
This works fine if I try on an open port, however if I check a closed port, I get:
[CptBartender@somewhere ~]$ <dev/tcp/host/blocked_port ; echo $?
-bash: connect: Connection refused
-bash: /dev/tcp/host/blocked_port: Connection refused
1
Now my next step was to try and discard the outputs of the first command, so I tried:
[CptBartender@somewhere ~]$ <dev/tcp/host/blocked_port >/dev/null/ 2>&1; echo $?
-bash: connect: Connection refused
-bash: /dev/tcp/host/blocked_port: Connection refused
1
Same output. My questions are, why is the first command printin any output whatsoever and how do I prevent it from doing so?