13

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
  • What does netstat -tln actually do? – nohillside Nov 24 '14 at 9:04
  • You can just open a Terminar an execute on it. It will work. – jherran Nov 24 '14 at 9:07
  • 1
    @jherran No, OS X is using a BSD-based netstat which accepts different sets of options. – lolski Nov 24 '14 at 9:13
  • @patrix in Linux, it lists all open TCP ports on the machine, and whether it listens locally (127.0.0.1) or to remote connections (0.0.0.0). – lolski Nov 24 '14 at 9:16
12

Should be this command:

sudo lsof -iTCP:$PORT -sTCP:LISTEN 

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

9

The closest equivalent you can get on OSX is:

netstat -p tcp -van | grep 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 effecitvely 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)

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .