How to determine what process has opened a network connection?

Whereas on Windows it's possible to use Netstat -b, which tells you what connections are open and what program has each one open, on the Mac it seems that Netstat does not allow this.

Is there another way to get this information if Netstat isn't the tool for that job?


> lsof -i :58199
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Transmiss 304 Fyodor    8u  IPv4 0x2fbc34fe135e3895      0t0  UDP *:58199

lsof = list open files. See manual for more details.

/usr/sbin/lsof

You can see with "ps -ef" more info about the PID "lsof" gave you.


To get the pid associated with each socket on OS X use the -v option for netstat

$ netstat -avnp tcp
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)     rhiwat shiwat    pid   pid
tcp6       0      0  *.3689                 *.*                    LISTEN      131072 131072   7541      0
tcp4       0      0  *.3689                 *.*                    LISTEN      131072 131072   7541      0
tcp46      0      0  *.3283                 *.*                    LISTEN      131072 131072    631      0
tcp4       0      0  *.88                   *.*                    LISTEN      131072 131072     87      0
tcp6       0      0  *.88                   *.*                    LISTEN      131072 131072     87      0