6

In Ubuntu, to see the listening process I used to do the following command netstat -pant I would get something similar to this

Credits to samclass.info

What is the equivalent command with the Mac ?

1 Answers1

10

(from this answer)

To show the processes, you would use netstat -vanp tcp. This doesn't translate the PIDs to process names, but you could do an awk using ps to translate them. Alternatively, you could go straight to sudo lsof -i tcp and get a slightly different layout that maps ports to named processes.

Here's an example (newlines added for readability):

netstat -vanp tcp |
  awk 'BEGIN { l=0 }
       { if (l == 0) { print $0 }
         else if (l == 1) { print $0, "process" }
         else { "ps -o comm " $9 "| tail -1" | getline line;
                print $0, line }
         l++; }'

If you want UDP results instead, just specify udp instead of tcp.

Ian MacDonald
  • 13,472
  • 2
  • 30
  • 51