Mac equivalent of `netstat -b -n`?
Is there an equivalent tool/shell command for Mac (preferably integrated with the OS) that has the functionality of the Windows command-line netstat -b -n? (displays active network connections, with the application that created them and source/dest IP+Port)
4 Answers
OS X has a netstat command, but it doesn't display information about the programs associated with the network connections. If you want to see that, you need to use lsof instead. Note that it must be run as root (i.e. with sudo) in order to see other users' programs:
sudo lsof -ilsof also has many options for controlling what's displayed:
sudo lsof -i tcp -nP # show TCP unly (no UDP), and don't translate IP addrs and ports numbers to names
sudo lsof -i 6tcp -stcp:listen # show only IPv6 TCP ports in the listen state
sudo lsof -i @10.11.12.13 # show only connections to/from 10.11.12.13...see the man page for more.
lsof lists open files, so if a process is on last-ack say, they wont be listed
netstat will not give pids on osx
utility does not work as suggested
so no answers are correct
there is no way as far as i can see to duplicate the functioning of cports on the mac
all other answers are misleading
Try nettop. It does exactly what you asked.
As already been pointed out, netstat is also available on Mac OS X as a command line tool.
If you prefer a GUI tool integrated with the OS, then you can use network utility located here: /Applications/Utilities/Network\ Utility.app
Besides netstat, it allows easy access to other network utilities as well. A good overview on the network utility can be found in the article "How to use Network Utility".