Check connection with netcat nc

If you’d like to check if a port is listening (e.g. typical usage in a bash script), you can use the following line:

After running this command, you can check the return code.

If $? is 0, the connection is up. If it’s 1, it’s not working.