How To Show Open Ports on OS X

How To Show Open Ports on OS X

netstat doesn't behave as it does on Linux. Here's how to show or list open ports on OS X:

$ sudo lsof -i -P | grep -i listen

I've set this up as an alias in my .profile (or .bashrc, depending on which shell you use) file as follows:

alias ports='sudo lsof -i -P | grep -i listen'