Created
May 5, 2016 20:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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