Sometimes you need to see which process is running on which port on your system. That may be out of pure curiosity, because an application you’re developing is complaining that the intended port is in use, or, dun dun dun, you have a backdoor accepting connections!
The tool we need is called netstat which is readily available on *nix systems and even micro$oft doze! If you find that your system doesn’t have netstat installed, here are some install commands to acquire said tool via the net-tools package:
MacOS’s netstat is a little different. Firstly, you can’t specify TCP and UDP traffic together; secondly, you have to pipe the output to grep in order to show only listening ports; and thirdly, and most importantly, you can’t get the PID of the process on a port. All is not lost however as you can get the PID with lsof That said, here is the best alternative for MacOS using netstat I could come up with: