lsof is very useful to get a quick grip of the current open ports on your machine. It can do much more, the name is short for “list open files”. You can see exactly which files are open and which process that opened them.
This lists all open files that are connecting over the network:
lsof -i -P
-Poption outputs port number and not port names.
-ishows files communicating over the network.
To filter out the open ports, use
lsof -i -P | grep -i "listen"