Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security, Veeam & DevOps

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form

Network statistics: How to save netstat command output to a text

Posted on 19/01/201917/08/2026 Christian By Christian 3 Comments on Network statistics: How to save netstat command output to a text
  1. Home
  2. Web Server
  3. Network statistics: How to save netstat command output to a text
Network statistics

In this article, we shall discuas “Network statistics: How to save netstat command output to a text”. The network statistics (netstat ) command is a networking tool used for troubleshooting and configuration. It can also serve as a monitoring tool for connections over the network. Both incoming and outgoing connections, routing tables, port listening, and usage statistics are common uses for this command. Please see How to logoff, restart, or shutdown Windows PC or Server remotely and how to configure OpenSSH Server.

Netstat is a cross-platform command, this means it’s also available in other operating systems like macOS and Linux.

Also, see “how to prevent a remote shutdown and restart in Windows 10″. Here is how to allow only admin users (administrators) to shut down and reboot Servers.

Netstat Command Syntax

Below is a table of the Netstat Command Syntax.

OptionExplanation
netstatExecute the netstat command alone to show a relatively simple list of all active TCP connections which, for each one, will show the local IP address (your computer). The foreign IP address (the other computer or network device), along with their respective port numbers, as well as the TCP state.
-aThis switch displays active TCP connections, TCP connections with the listening state, as well as UDP ports that are being listened to.
-bThis netstat switch is very similar to the -o switch listed below, but instead of displaying the PID, will display the process’s actual file name. Using -b over -o might seem like it’s saving you a step or two but using it can sometimes greatly extend the time it takes netstat to fully execute.
-eUse this switch with the netstat command to show statistics about your network connection. This data includes bytes, unicast packets, non-unicast packets, discards, errors, and unknown protocols received and sent since the connection was established.
-fThe -f switch will force the netstat command to display the Fully Qualified Domain Name (FQDN) for each foreign IP address when possible.
-nUse the -n switch to prevent netstat from attempting to determine hostnames for foreign IP addresses. Depending on your current network connections, using this switch could considerably reduce the time it takes for netstat to fully execute.
-oA handy option for many troubleshooting tasks, the -o switch displays the process identifier (PID) associated with each displayed connection. See the example below for more about using netstat -o.
-pUse the -p switch to show connections or statistics only for a particular protocol. You can not define more than one protocol at once. Nor can you execute netstat with -p without defining a protocol.
protocol When specifying a protocol with the -p option, you can use tcp, udp, tcpv6, or udpv6. If you use -s with -p to view statistics by protocol, you can use icmp, ip, icmpv6, or ipv6 in addition to the first four I mentioned.
-rExecute netstat with -r to show the IP routing table. This is the same as using the route command to execute route print.
-sThe -s option can be used with the netstat command to show detailed statistics by protocol. You can limit the statistics shown to a particular protocol by using the -soption and specifying that protocol. But be sure to use -s before -p protocol when using the switches together.
-tUse the -t switch to show the current TCP chimney offload state in place of the typically displayed TCP state.
-xUse the -x option to show all NetworkDirect listeners, connections, and shared endpoints.
-yThe -y switch can be used to show the TCP connection template for all connection. You cannot use -y with any other netstat option.
time_intervalThis is the time, in seconds, that you’d like the netstat command to re-execute automatically. Stopping only when you use Ctrl-C to end the loop.
/?Use the help switch to show details about the netstat command’s several options.

For clarity said due to the recent comment i received, here are some screenshoots of a new test.

netstat -an > yourtextoutputfilename.txt
Screenshot-2021-03-01-at-11.38.54

Also, see  how to prevent users from shutting down in a Virtual Machine and Handy Command-Prompt Shutdown Commands.

Here is a fix for “Telnet is not recognized as an internal or external command“.

Save netstat command output to a text

Run any netstat command you desire and add the following parameters to get the text output.

Screenshot of a command line interface displaying commands related to a text file named 'ports.txt' on a desktop.

Entering another text output

netstat command

File created for the network stats.

netstat command

I hope you found this blog post on “Network statistics: How to save netstat command output to a text” helpful. Please let me know in the comment session if you have any questions.

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
Web Server, Windows Server Tags:troubleshooting, Windows 10

Post navigation

Previous Post: Stop TeamViewer from starting Automatically
Next Post: How does IP Address or Domain blacklist work?

Related Posts

  • windows subsystem
    What is Windows Subsystem for Linux Windows Server
  • Windows Admin Center v2511
    How to upgrade Windows Admin Center from v2411 to v2511 Windows Server
  • Migrate from SQL Database
    Migrate Veeam One Database from SQL Server 2017 to 2025 Backup
  • Configure Windows Server with Sconfig
    How to Configure Windows Server Core using SConfig Windows
  • Screenshot 2020 05 19 at 02.57.10
    Create Central Store for Group Policy Administrative Templates Windows Server
  • RDP Certificate Issues
    Connecting to the RDP host: Fix the Certificate could not be verified back to the root certificate Mac

More Related Articles

windows subsystem What is Windows Subsystem for Linux Windows Server
Windows Admin Center v2511 How to upgrade Windows Admin Center from v2411 to v2511 Windows Server
Migrate from SQL Database Migrate Veeam One Database from SQL Server 2017 to 2025 Backup
Configure Windows Server with Sconfig How to Configure Windows Server Core using SConfig Windows
Screenshot 2020 05 19 at 02.57.10 Create Central Store for Group Policy Administrative Templates Windows Server
RDP Certificate Issues Connecting to the RDP host: Fix the Certificate could not be verified back to the root certificate Mac

Comments (3) on “Network statistics: How to save netstat command output to a text”

  1. Avatar photo John says:
    01/03/2021 at 11:01 AM

    Doesn’t work

    Log in to Reply
    1. chris Christian says:
      01/03/2021 at 11:44 AM

      What exactly did not work? I am not sure you are very familiar with how this tool works and where to locate the outputted text file.

      I have appended the new test result to the end of this article.

      Log in to Reply
      1. Avatar photo Kyle says:
        04/11/2022 at 7:46 PM

        it stops execution when redirect. For example if i run “netstat -a” it runs indefinitely but if run netstat -a > file.txt it runs for a few seconds and ends

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

Veeam Vanguard

  • macos app switcher shortcuts
    How to enable or disable automatic software updates on Mac Mac
  • cv
    Add languages to Windows images using DISM and PowerShell Windows Server
  • self signed sslcert
    Generate self-signed certificate and export in PFX format via PowerShell [Part 2] Windows
  • Temp Files
    Recover Temp Files using Disk Drill etc on Windows 10 and 11 Windows
  • MBAM Client
    How to Check if MBAM Agent is installed on Windows PC Windows
  • wacxx
    How to set up System Insights on Windows Admin Center Windows Server
  • exchange 2016 1
    Failed Edge Transport: Easy Guide For Removal Network | Monitoring
  • ext
    How to install a standalone DriveLock Encryption software on Windows Security | Vulnerability Scans and Assessment

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,762 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Contact
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon
  • Bsky

Tags

Active Directory Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2026 TechDirectArchive

Loading Comments...

You must be logged in to post a comment.