using netstat
we can find LISTENing or open port etc.
I want to know how can we find out which process has opened which port we see in the result of
netstat -vanp tcp
macosNetwork
using netstat
we can find LISTENing or open port etc.
I want to know how can we find out which process has opened which port we see in the result of
netstat -vanp tcp
Best Answer
As @klanomath mentioned in a comment, the output from
netstat -vanp tcp
contains the process ID of the process that has the port open (it's the next-to-last field), so you can look it up by that:So in this example, it's cupsd (the Common UNIX Printing System Daemon) listening on port 631 (for IPP, the Internet Printing Protocol).
You can also use
lsof -i
, with many options to narrow down the search; see man lsof for details. But note that you need to run it as root (i.e. withsudo
) to see processes you don't own: