What is the equivalent of netstat -tln on OS X?

What is the equivalent of Linux's netstat -tln on OS X?

Options:

-l, --listening (Show only listening sockets. (These are omitted by default.)
--numeric , -n (Show numerical addresses instead of trying to determine symbolic host, port or user names.)
-t, --tcp

Should be this command:

sudo lsof -iTCP:$PORT -sTCP:LISTEN 

Who is listening on a given TCP port on Mac OS X?


The closest equivalent you can get on macOS is:

netstat -p tcp -van | grep '^Proto\|LISTEN'
  • tu options are not available, but they can be replaced by either -p tcp or -p udp, although you can't have both at the same time
  • -p option is replaced with -v which effectively gets you PIDs listed
  • -l option is not available, but you can work around it by using -a option (which includes servers in the listing) and grep LISTEN (to filter only for listening)