netstat -ntlp
or
ss -ntlp
netstat -anob
go and install (you can use macports too!)
brew install iproute2mac
and now run
ss -ntlp
I hear your frustration 😅 — Linux feels straightforward with ss and netstat, but macOS and Windows definitely make you jump through different hoops. Let’s break it down clearly so you can see the equivalents without the headache.
ss -ntlp→ shows TCP sockets with process info.netstat -ntlp→ older but similar.
macOS doesn’t ship ss or netstat -p. Instead, you use lsof or netstat (but with fewer options):
-
List listening ports with processes:
lsof -iTCP -sTCP:LISTEN -n -P
-iTCP→ only TCP sockets-sTCP:LISTEN→ only listening sockets-n -P→ don’t resolve hostnames/ports (faster, clearer)
-
Alternative with
netstat:netstat -anv | grep LISTENBut this won’t show the owning process — that’s why
lsofis the go-to.
👉 Tip: If you want something more intuitive, install ss via Homebrew:
brew install iproute2macThen you can use ss just like on Linux.
- Show active connections and listening ports:
netstat -ano-a→ all connections and listening ports-n→ numeric addresses-o→ include process ID (PID)
Then you can match the PID with:
tasklist /FI "PID eq 1234"Yes, the syntax looks weird at first — but it’s powerful once you get used to it.
- List TCP connections:
Get-NetTCPConnection - Filter listening ports:
Get-NetTCPConnection | Where-Object { $_.State -eq "Listen" }
- Match PID to process:
Get-Process -Id 1234
👉 The capital letters aren’t mandatory — PowerShell is case-insensitive. You can type get-nettcpconnection in lowercase and it works fine. The - parameters are just PowerShell’s way of being explicit.
| OS | Command for listening ports + PID |
|---|---|
| Linux | ss -ntlp |
| macOS | lsof -iTCP -sTCP:LISTEN -n -P |
| Windows | netstat -ano + tasklist OR Get-NetTCPConnection |
So:
- On macOS, stick with
lsofor installssvia Homebrew. - On Windows,
netstat -anois closest to Linux, while PowerShell gives you richer filtering once you get past the syntax.
Would you like me to write you a one-liner cheat sheet that shows “listening ports + process name” for each OS side by side, so you don’t have to remember the details?