39

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
lolski
  • 515

3 Answers3

39

Should be this command:

sudo lsof -iTCP:$PORT -sTCP:LISTEN 

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

jherran
  • 13,284
  • 1
    OP question didn't have a port argument, this answer requires one. This gives a useful command https://apple.stackexchange.com/a/327967/209603 – goetz Dec 06 '18 at 18:31
  • 6
    @goetzc Just use -iTCP instead of -iTCP:$PORT. – Navin Dec 24 '18 at 09:00
  • 4
    I would add -P since OP specified -n in their question. Also +1 to @Navin. sudo lsof -iTCP -sTCP:LISTEN -P is closer to netstat -tln – seeafish Nov 07 '19 at 15:28
27

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)
ysth
  • 143
6

For real-time monitoring, try this:

nettop -p 60683

You can also restrict the interface type, like wifi or wired...

nettop -t wifi -n -p 60683
Iceberg
  • 301