Netstat Mac OS X How To List all listening sockets w/ Process Names

Posted by tomachi on January 12th, 2016 filed in Mac, Unix

Just quickly show all open connections:

netstat -Wltn | grep tcp

Still fast but show every internet port with no DNS lookups:
netstat -Waltn | grep -E "(tcp|udp)(4|6)"

Like above but with DNS lookups but takes literally forever up to minutes:

netstat -Walt | grep -E "(tcp|udp)(4|6)"

Show only servers - that is ports that are listening waiting for an inbound connection:

netstat -Waltn | grep LISTEN

The Little Snitch Command - Who's phoning home?

How to use LSOF to discover which app or process is listening to which ports:

lsof -Pnl +M -i -cmd | grep -E "LISTEN|TCP|UDP"

I prefer to use -n to speed up the listing of netstat results by turning off DNS lookups ip to name resolution. The l is used to also show ipv6. To show all internet connections, whether ipv4 or ipv6, tcp or udp, listening, connected or closing - the lot:

netstat -Waltn | grep p[46]

Show only TCP connections:

netstat -anp tcp

To see which apps have listening sockets open:

sudo lsof  -n -P | grep LISTEN

Some other good linux ones here: http://www.commandlinefu.com/commands/matching/netstat/bmV0c3RhdA==/sort-by-votes

Show Process ID in Netstat Mac

Actually, you can't but you can use LSOF which lists open files and sockets:

lsof -Pnl +M -i

Use -i4 for ip4 and -i6 for ip6. -i seems to work for all internet traffic.

Linux

sudo netstat -tulpn

Comments are closed.