commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
netstat will list all open ports on the system, unix sockets, tcp sockets and udp sockets. the t flag limits to tcp ports the l flag limits to listening ports and the n flag disables the translation of port to service ( ie :25 displayed instead of :smtp ). then grep for the port you are interested in preceeded by a colon.
There are 4 alternatives - vote for the best!
Check trough unix sockets if tcp port is open or close
Using netcat (nc)
25 can be replaced with the friendly value (smtp). Check error code for result or use -v option to echo output
nc -z localhost smtp && echo open || echo closed
nc -zv host protocol
If you can do better, submit your command here.
You must be signed in to comment.