The netstat (network statistics) command in Windows is a command-line tool used to display all active TCP connections, ports on which the computer is listening, Ethernet statistics, the IP routing table, and IPv4/IPv6 statistics. To use it, open the Command Prompt and type netstat followed by specific switches to filter the data you need. This tool is essential for diagnosing connectivity issues, identifying unauthorized connections, and verifying that specific applications are communicating over the network.
What You'll Need
- A computer running a version of Windows (such as Windows 10 or Windows 11).
- Administrative privileges (required for certain switches, such as viewing the Process ID).
- Access to the Command Prompt or Windows PowerShell.
Step-by-Step
- Open the Command Prompt as Administrator
Click the Start button, type "cmd" into the search bar. Right-click on "Command Prompt" and select "Run as administrator". This is a critical step because viewing the Process ID (PID) associated with a connection requires elevated permissions. If you run it as a standard user, the PID column will remain blank or return an error for system-level processes. - Run a Basic Connection Scan
Typenetstatand press Enter. This provides a basic list of all active connections. You will see the "Proto" (Protocol), "Local Address", "Foreign Address", and "State". The state tells you if a connection is "Established" (currently active) or "Close_Wait" (waiting to be closed). - Display All Active Ports and Listening Ports
Typenetstat -aand press Enter. The-aswitch stands for "all". Unlike the basic command, this shows not only established connections but also ports that are "Listening". A listening port is one that is open and waiting for an incoming connection from another device or service. - Identify the Application Using a Port (PID)
Typenetstat -anoand press Enter. This is one of the most useful combinations of switches.-adisplays all connections and listening ports.-ndisplays addresses and port numbers in numerical form. This prevents Windows from attempting to resolve IP addresses to hostnames, which makes the command run significantly faster.-odisplays the owning Process ID (PID) associated with each connection.
- Find the Application Name via Task Manager
Once you have the PID from the previous step, you need to know which program that ID belongs to. Right-click the Taskbar and select "Task Manager". Go to the "Details" tab. Look for the "PID" column. Match the number from yournetstat -anooutput to the PID in Task Manager to see exactly which .exe file is using that network port. - Monitor Connections in Real-Time
Typenetstat -an 5and press Enter. Replacing the number 5 with any other integer tells Windows to refresh the list every X seconds. This is helpful for spotting a connection that only appears briefly when a specific app starts or when a website is pinged. Press Ctrl+C to stop the loop. - View Routing Tables and Statistics
To see how your computer is routing traffic, typenetstat -r. This displays the same information as theroute printcommand. To see a summary of statistics for TCP, UDP, IP, and ICMP, typenetstat -s. This is useful for identifying "packet loss" or "retransmission errors" which indicate a poor quality network connection.
Common Mistakes
One of the most frequent mistakes is running the Command Prompt without administrator rights. When using the -o switch to find the Process ID, a non-admin prompt will often fail to show the PIDs for system services or applications launched by other users, leaving the user confused as to why the PID column is empty. Always ensure the window title says "Administrator: Command Prompt".
Another common error is forgetting the -n switch. By default, netstat tries to perform a reverse DNS lookup to turn IP addresses (like 142.250.190.46) into names (like google.com). If your DNS server is slow or the connection is unstable, the command will appear to "freeze" or hang for several minutes while it waits for those names to resolve. Using -n forces numerical output and provides an instant result.
Users also often confuse "Listening" with "Established". A port in the "Listening" state is not necessarily communicating with anyone; it is simply a door that is open. An "Established" connection means data is actually being exchanged between your PC and a remote server. If you see a port listening but no established connections, it does not mean your computer is currently being accessed by an outside party.
Tips
To make the output easier to manage, use the "findstr" command to filter for a specific port. For example, if you want to see if port 80 (HTTP) is active, type netstat -ano | findstr :80. This pipes the output of netstat into a search tool that only displays lines containing ":80", saving you from scrolling through hundreds of lines of data.
If you need to save your network logs for later analysis or to send to a technician, you can export the results to a text file. Type netstat -ano > network_log.txt. This creates a file in your current directory containing the full output of the command. You can then open this file in Notepad for easier searching and documentation.
For a more visual approach, remember that netstat is the command-line equivalent of the "Resource Monitor". You can access this by typing "Resource Monitor" in the Start menu and clicking the "Network" tab. While netstat is faster for scripts and quick checks, Resource Monitor provides a graphical view of which processes are sending and receiving the most bytes per second.
Troubleshooting
If the netstat command is not recognized as an internal or external command, your system's PATH environment variable may be corrupted. The netstat.exe file is located in C:\Windows\System32. You can try running the command by typing the full path: C:\Windows\System32\netstat.exe -ano. If this works, you will need to repair your system environment variables in the Advanced System Settings menu.
If you see a large number of connections in the "TIME_WAIT" state, do not panic. This is a normal part of the TCP protocol. It means the connection has been closed, but the system is keeping the socket open for a short period to ensure any delayed packets are received before the port is fully released. However, if thousands of these appear simultaneously, it could indicate a "port exhaustion" issue caused by a buggy application opening and closing connections too rapidly.
If you find a connection to an unknown foreign IP address and suspect malware, do not immediately delete system files. Copy the foreign IP address and paste it into a reputable "Whois" lookup tool online. This will tell you who owns the IP. Many "unknown" connections are simply background telemetry for Windows, updates for your graphics driver, or connections to a Content Delivery Network (CDN) used by legitimate websites.
Frequently Asked Questions
What is the difference between TCP and UDP in netstat?
TCP (Transmission Control Protocol) is connection-oriented, meaning it establishes a formal handshake before sending data, which is why you see states like "Established". UDP (User Datagram Protocol) is connectionless; it sends packets without verifying receipt, so UDP entries in netstat typically do not show a state like "Established".
Can netstat find a virus on my computer?
Netstat cannot identify a virus directly, but it can show "symptoms". If you see an established connection to a suspicious foreign IP address that persists even when all your browsers and apps are closed, it may indicate a trojan or botnet agent communicating with a Command and Control (C2) server.
Why are some ports listed as 0.0.0.0?
An address of 0.0.0.0 in the Local Address column means the service is listening on all available network interfaces. This includes your Ethernet port, your Wi-Fi adapter, and your local loopback (localhost). It is a way for a program to say, "I will accept connections from any IP address assigned to this machine."
What does the loopback address 127.0.0.1 mean?
The address 127.0.0.1 is the local loopback address. When you see this in netstat, it means a program on your computer is communicating with another program on the same computer. This is common for local development servers or internal software components that use network protocols to talk to each other without leaving the physical machine.
How do I stop a connection I found using netstat?
Netstat only monitors connections; it cannot kill them. To stop a connection, you must terminate the process associated with it. Find the PID using netstat -ano, then open Task Manager, go to the Details tab, right-click the process with that PID, and select "End Task".