I would like to check if I can connect to a port or not from within a bash script
Based on the answer to a similar question I tried running
nc -zvw10 <host> <port>
and check if the status code is 0/1
but many times it returns "Connection refused" and exits the script (there doesnt seem to be a return code)
I only want to exit the script if it returns a 0, which means a connection is made.