>_ Exploit the Edge

Home › Cybersecurity

Netstat on Windows: Useful Flags and Modern Alternatives

Published 30 Nov 2026 · 7 min read

What does netstat show on Windows?

Windows netstat displays active TCP connections and, depending on the options supplied, listening ports, Ethernet statistics, the routing table, protocol statistics, process IDs and associated executables. It is useful for answering three immediate questions:

  • Which local ports are listening?
  • Which remote addresses is this machine connected to?
  • Which process owns a connection or listener?

This guide focuses on Windows because options such as -b, -f and -o are defined by Microsoft's implementation. Linux and macOS versions use different option sets, so commands should not be copied between operating systems without checking their manual pages.

Open Command Prompt, Windows Terminal or PowerShell and start with:

netstat -ano

This is usually more useful than bare netstat: it includes listening ports, keeps addresses numerical and displays the owning process ID.

What do the main netstat flags mean?

Option What Windows netstat displays Practical use
-a Active TCP connections plus listening TCP and UDP ports Find exposed services and active sessions
-n Addresses and port numbers numerically Avoid name resolution and preserve exact IP addresses
-f Fully qualified domain names for foreign addresses Make some remote endpoints easier to recognise
-b The executable involved in creating each connection or listener Associate network activity with software
-o The owning process ID for each connection Correlate output with Task Manager or PowerShell
-p Connections for a specified protocol Limit output to TCP, UDP, TCPv6 or UDPv6 where supported
-r The IP routing table Diagnose route and gateway problems
-s Per-protocol statistics Inspect TCP, UDP, IPv4, IPv6 and related counters
-e Ethernet statistics Check byte and packet totals, discards and errors

Microsoft notes that -b can be time-consuming and can fail unless the account has sufficient permissions. Run an elevated terminal when you need executable information.

How to list every connection and listening port

Use -a to include listening TCP and UDP ports as well as active TCP connections:

netstat -a

The output contains local and foreign endpoints. TCP rows also include a state such as LISTENING, ESTABLISHED or TIME_WAIT. UDP is connectionless, so its rows do not have equivalent TCP connection states.

For incident triage, combine -a with -n:

netstat -an

Numerical output avoids replacing IP addresses and ports with names. It also makes the evidence less ambiguous: you retain the endpoint that netstat observed rather than a resolved hostname that may change or map to several addresses.

To show only TCP or UDP entries, use the protocol option:

netstat -an -p tcp
netstat -an -p udp

How to identify which process owns a port

The -o option adds the owning process ID, or PID:

netstat -ano

If port 8443 is under investigation, filter the output without assuming that the first match is malicious:

netstat -ano | findstr ":8443"

Then look up the PID shown in the final column:

Get-Process -Id 1234

Replace 1234 with the observed PID. You can also use the built-in tasklist command:

tasklist /FI "PID eq 1234"

A listening port is not, by itself, evidence of compromise. Confirm the process name, executable location, service configuration and whether the port is reachable through the host firewall before deciding what to do.

How to show the executable behind each connection

Use -b from an elevated terminal:

netstat -abno

This combines four useful views:

  • -a: all active connections and listening ports
  • -b: associated executables
  • -n: numerical endpoints
  • -o: owning PIDs

Microsoft describes -b as showing the executable involved in creating each connection or listening port. For some well-known executables, netstat may also display a sequence of components involved until TCP/IP is reached.

Do not treat the executable name as sufficient attribution. Use the PID to inspect the actual process and executable path:

Get-CimInstance Win32_Process -Filter "ProcessId = 1234" |
    Select-Object ProcessId, Name, ExecutablePath, CommandLine

Administrative rights may be required to retrieve information about processes owned by another account or protected by the operating system.

What does netstat -f do?

On Windows, -f displays fully qualified domain names for foreign addresses:

netstat -f

It can be combined with executable output:

netstat -b -f

The original article described this combination as revealing an executable's full path. That is not what Microsoft's documentation promises: -f affects the presentation of foreign addresses, while -b identifies involved executables. Use the PID and process-management tools when you need the executable path.

Hostname output is useful context, not proof of identity. DNS information can change, several names can resolve to one address, and one name can resolve to several addresses. Preserve numerical output when collecting evidence.

How to refresh netstat output continuously

Windows netstat accepts an interval in seconds as its final argument. For example, this command redisplays numerical connections and PIDs every five seconds:

netstat -ano 5

Press Ctrl+C to stop it.

This is a repeating snapshot, not a durable monitoring system. For a short capture with timestamps, PowerShell can record successive samples:

1..12 | ForEach-Object {
    "=== $(Get-Date -Format o) ==="
    netstat -ano
    Start-Sleep -Seconds 5
} | Out-File -FilePath "$env:USERPROFILE\Desktop\netstat-capture.txt" -Encoding utf8

This records roughly one minute of output. Review the file for new listeners, repeated outbound destinations or short-lived connections, then correlate relevant PIDs with process details. A connection can end before you investigate it, and Windows can later reuse its PID, so capture process information promptly.

A cleaner PowerShell alternative

Get-NetTCPConnection returns TCP connection objects rather than formatted text. That makes it easier to filter and export results reliably:

Get-NetTCPConnection |
    Sort-Object State, LocalPort |
    Format-Table LocalAddress, LocalPort, RemoteAddress, RemotePort, State, OwningProcess

Show listening TCP sockets only:

Get-NetTCPConnection -State Listen |
    Sort-Object LocalPort |
    Format-Table LocalAddress, LocalPort, OwningProcess

Add process names while keeping addresses and ports in separate properties so IPv6 endpoints remain unambiguous:

Get-NetTCPConnection -State Established | ForEach-Object {
    $process = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
    [pscustomobject]@{
        LocalAddress  = $_.LocalAddress
        LocalPort     = $_.LocalPort
        RemoteAddress = $_.RemoteAddress
        RemotePort    = $_.RemotePort
        State         = $_.State
        PID           = $_.OwningProcess
        ProcessName   = $process.ProcessName
    }
} | Format-Table -AutoSize

Exporting objects to CSV is preferable to scraping aligned netstat text:

Get-NetTCPConnection |
    Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort, State, OwningProcess |
    Export-Csv "$env:USERPROFILE\Desktop\tcp-connections.csv" -NoTypeInformation

For a live graphical view, Microsoft's Sysinternals TCPView lists TCP and UDP endpoints and reports the process that owns each endpoint. It is better suited to interactive monitoring; netstat remains useful on systems where you only have built-in command-line tools.

What should Linux users use instead?

The Linux netstat command belongs to the older net-tools suite. The ss utility from iproute2 provides socket inspection on current Linux systems.

A closer Linux functional match for Windows netstat -ano is:

sudo ss -tunap

The options request TCP sockets, UDP sockets, numerical addresses, all socket states and process information. Platform and privilege differences still apply, and process details may be incomplete without sufficient permissions.

To restrict the output to listening TCP and UDP sockets, use:

sudo ss -tulpn

The -l option limits ss to listening sockets, so this command does not include active TCP connections and is not a direct equivalent of Windows netstat -ano. Linux flags are not interchangeable with Windows netstat flags; for example, -p has different meanings between these tools.

How to investigate an unexpected connection safely

Do not terminate a process solely because its destination or port is unfamiliar. Use this workflow instead:

  1. Capture netstat -abno from an elevated terminal.
  2. Record the complete local and remote endpoints, state, PID and executable name.
  3. Inspect the PID with Get-Process and Get-CimInstance.
  4. Check whether the executable is expected, signed and stored in an appropriate directory.
  5. Review the service or scheduled task that launched it, if applicable.
  6. Check Windows Firewall rules and whether a listening port is reachable from other networks.
  7. If compromise is plausible, preserve evidence and isolate the device through your incident-response process rather than deleting files immediately.

Useful first checks include:

Get-AuthenticodeSignature "C:\Path\To\Program.exe"
Get-NetFirewallRule -Enabled True | Select-Object DisplayName, Direction, Action

A valid signature does not prove that a process is safe, and an unsigned executable is not automatically malicious. These are investigation signals that must be considered alongside the path, parent process, command line and expected system role.

Commands worth keeping nearby

# All connections, listeners and PIDs, with numerical addresses
netstat -ano

# Add associated executables; run elevated
netstat -abno

# Find references to a particular port
netstat -ano | findstr ":443"

# Resolve a PID to a process
Get-Process -Id 1234

# Inspect the process path and command line
Get-CimInstance Win32_Process -Filter "ProcessId = 1234" |
    Select-Object ProcessId, Name, ExecutablePath, CommandLine

# Structured list of listening TCP sockets
Get-NetTCPConnection -State Listen

# Display netstat's built-in help
netstat /?

What changed since the original

The 2023 article treated netstat flags as broadly portable, but -b and the described behaviour of -f are specific to Windows. This revision narrows the flag guide to Windows, corrects the claim that -bf reveals an executable's full path, adds PID correlation with -o, and recommends PowerShell, TCPView and Linux ss where they provide a better workflow.

Practical next steps

  • Run netstat -ano during a known-good system state, but treat it as a time-stamped reference rather than a stable baseline. Connections and PIDs are transient, so collect repeated samples and compare persistent listeners, expected services and recurring destinations instead of expecting snapshots to match exactly.
  • Map unfamiliar listening ports to their PIDs and executable paths.
  • Use Get-NetTCPConnection when you need filtering or CSV export.
  • Use elevated netstat -abno only when executable attribution is necessary.
  • Investigate context before blocking an address or terminating a process.

FAQ

What does netstat -ano show on Windows?

It shows active TCP connections, listening TCP and UDP ports, numerical addresses and ports, and the owning process ID. Use the PID with Get-Process or Get-CimInstance to identify the associated process.

Does netstat -b show the full executable path?

Microsoft documents -b as showing the executable involved in creating each connection or listener, not as a reliable way to retrieve its full path. Use the owning PID with Get-CimInstance when you need the executable path and command line.

Is Get-NetTCPConnection better than netstat?

It is better when you need structured PowerShell objects, filtering, sorting or CSV export. Netstat remains useful for quick checks and on systems where only built-in command-line tooling is available.

What is the Linux equivalent of netstat -ano?

The closer functional match is `sudo ss -tunap`, subject to Linux privilege and platform differences. `sudo ss -tulpn` adds `-l`, which restricts the output to listening sockets and therefore omits active TCP connections.

Can a netstat snapshot be used as a baseline?

Only as a time-stamped reference. Connections and PIDs change frequently, so a useful baseline should rely on repeated samples and focus on persistent listeners, expected services and recurring destinations rather than exact snapshot matches.

Sources

  1. Microsoft Learn: netstat
  2. Microsoft Learn: Get-NetTCPConnection
  3. Microsoft Learn: Get-Process
  4. Microsoft Learn: Get-CimInstance
  5. Microsoft Learn: TCPView
  6. Microsoft Learn: Get-AuthenticodeSignature
  7. Microsoft Learn: Get-NetFirewallRule
  8. Linux manual page: ss(8)