I want to see if something is listening on a port on localhost. I was going to use
nc and check the exit code.
Something like this:
echo "" | nc localhost 14881 echo $?
Any other suggestions?
Maybe netstat would be better because the port might not be listening on localhost or it might be blocked by iptables:
Grep will exit with 1 if there is no match. If you want just tcp and/or udp , add the -u or -t switches to netstat.