I always have to google this and ServerFault is never the first result. Typically I want to do this on a unix box, but I'd also like to know how to do it on a Windows machine from CMD.exe.


Use netstat -pl on Unix. Option -p shows process PID/name and option -l shows only listen sockets.

On Windows, use netstat -oa. Option -o is the same as -p on Unix. Option -a is also the same on Unix, it shows all sockets. You'll have to look only at LISTENING lines since Windows' netstat doesn't provide an option to show only listen sockets.

If you don't want to resolve IP addresses to name (which can take a great amount of time), use option -n

| improve this answer | |
  • And on Mac OS X, you can use sudo lsof -i -P | grep -i 'listen' – Bert Mar 9 '14 at 16:50
  • Also, if you want less work on windows, you can pipe netstat's output and search for a string. Running netstat -nao | find "LISTEN" returns only the listening ports on your machine without you having to dig line by line througt things. – Jason Mar 11 '14 at 20:26

netstat -nap ( linux ) netstat -nao ( windows )

Look for "LISTEN" lines, you have even the process which is listening.

| improve this answer | |

Your Answer

