How to Determine What Program Is Listening on a Port in OS X or Linux

To determine what daemon or program is listening on a port in Linux or OS X you can use the lsof command. You need to run the command while logged in as root or if your operating system supports sudo like OS X, you can use that.

Command to run in Linux:

lsof -i -nP

Command to run in OS X:

sudo lsof -i -nP