Skip to content

Instantly share code, notes, and snippets.

@parsaM110
Last active November 14, 2025 11:59
Show Gist options
  • Select an option

  • Save parsaM110/5634b9aaf3210fb88e8af9d10fe3b3fc to your computer and use it in GitHub Desktop.

Select an option

Save parsaM110/5634b9aaf3210fb88e8af9d10fe3b3fc to your computer and use it in GitHub Desktop.
network monitoring in OSs

linux

netstat -ntlp

or

ss -ntlp

windows

netstat -anob

mac

go and install (you can use macports too!)

brew install iproute2mac

and now run

ss -ntlp

Sources

chat

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.


🐧 Linux (your baseline)

  • ss -ntlp → shows TCP sockets with process info.
  • netstat -ntlp → older but similar.

🍏 macOS

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 LISTEN

    But this won’t show the owning process — that’s why lsof is the go-to.

👉 Tip: If you want something more intuitive, install ss via Homebrew:

brew install iproute2mac

Then you can use ss just like on Linux.


🪟 Windows

CMD

  • 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"

PowerShell

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.


⚡ Quick Comparison

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 lsof or install ss via Homebrew.
  • On Windows, netstat -ano is 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment