Skip to content

Instantly share code, notes, and snippets.

@mckartha
Created May 5, 2016 20:53
Show Gist options
  • Save mckartha/3725a1f2a82ce9b8c7bbbac28861903a to your computer and use it in GitHub Desktop.
Save mckartha/3725a1f2a82ce9b8c7bbbac28861903a to your computer and use it in GitHub Desktop.
Use `netstat` and `lsof` to find out which command/process is listening on a port on OS X
It is often useful to figure out which OS X command/process is listening on a specific IP port
On Linux this can be done with the `netstat -p`
On OS X, the process id along with a lot of other info can be can be shown using the verbose `-v` flag:
* `sudo netstat -anlv |grep -e Address -e LISTEN` - will display the LISTENing processes along with the column header
This variant outputs a comman-delimited list of the processes that are LISTENing:
* `sudo netstat -anlv |grep -e LISTEN | awk '{print $9}'| sort -nu| tr "\n" "," | sed s/,$//`
This can also be done using `lsof` - perhaps easier because it displays both the Command and PID:
* `sudo lsof -iTCP -sTCP:LISTEN -n -P`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment