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?
|
I want to see if something is listening on a port on localhost. I was going to use Something like this:
Any other suggestions?
| |||
feedback
|
|
lsof -i :14881 | |||||
|
feedback
|
|
If you are root:
| |||
feedback
|
|
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. | ||||
|
feedback
|
|
netstat -ano | egrep LISTEN | egrep tcp | egrep $PORTNUMBER | |||||
feedback
|