COMMAND

netstatActive connections and listening ports

netstat shows the machine's active TCP and UDP connections and the ports it is listening on. The combination netstat -ano lists every connection with its state and the owning process ID, which is how you find out which program is using a given port. Add findstr to filter by port number.

BlackhawkHub Editorial · Updated

Purpose

netstat (network statistics) reveals what a machine is doing on the network: which remote hosts it is connected to, which local ports are open and listening, and, with the right options, which process is responsible. It is the tool for answering "what is using port 8080?" and "is my server actually listening?".

Syntax

text
netstat [-a] [-n] [-o] [-b] [-p proto] [-r] [-s] [interval]

Essential options

OptionEffect
-aAll connections and listening ports
-nNumeric; do not resolve names (faster, clearer)
-oShow the owning process ID (PID)
-bShow the executable (needs admin)
-p tcp / -p udpFilter by protocol
-rRouting table (same as route print)
-sPer-protocol statistics
5Repeat every 5 seconds

The command you will use most

cmd
netstat -ano | findstr :443
text
  TCP    0.0.0.0:443            0.0.0.0:0              LISTENING       4
  TCP    192.168.1.37:52344     93.184.215.14:443      ESTABLISHED     8210

The last column is the PID. Identify it:

cmd
tasklist /fi "PID eq 8210"

See tasklist and, to stop it, taskkill.

Connection states

StateMeaning
LISTENINGA local program is waiting for connections on this port
ESTABLISHEDAn active connection
TIME_WAITRecently closed; waiting for stray packets (see ephemeral ports)
CLOSE_WAITThe remote end closed; the local app has not yet
SYN_SENTA connection attempt is in progress

Examples

Is my server listening where I expect?

cmd
netstat -ano | findstr LISTENING

A missing entry for your port explains a 502 Bad Gateway from a proxy in front of it.

Everything with executables (elevated):

cmd
netstat -anob

Protocol statistics (retransmissions, errors):

cmd
netstat -s -p tcp

Common mistakes

  • Forgetting -n, so netstat tries reverse DNS on every address and hangs.
  • Reading the source port as the service. 192.168.1.37:52344 is your ephemeral port; the service is the destination port.
  • Expecting -b without elevation.

PowerShell equivalent

Get-NetTCPConnection -State Listen | Sort-Object LocalPort lists listeners as objects; join with Get-Process on OwningProcess to get names. See Get-NetTCPConnection.

Frequently asked questions

How do I find which process is using a port?

Run netstat -ano | findstr :PORT, read the PID in the last column, then tasklist /fi "PID eq PID" or open Task Manager's Details tab and match the PID.

What is the difference between -a and -an?

-a shows all connections and listening ports; -n prevents netstat from resolving addresses and ports to names, which is faster and clearer. -ano adds the owning process ID. Use -ano in almost every case.

Why does netstat -b say access denied?

Showing the executable name (-b) requires administrator rights. Run the command from an elevated prompt, or use -ano and look the PID up separately.

Sources