Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Contact
  • Reviews
  • Toggle search form
Home » Windows Server » Network statistics: How to save netstat command output to a text
  • Featured Image new
    Add Registry Keys via DISM in Windows Windows
  • Disable download in Microsoft Edge
    How to disable file download in Microsoft Edge Windows
  • winSEARCH
    Hide or Remove Search Button from Windows 10 Taskbar Windows
  • Extend C drive with additional Software
    Fix unable to Extend Volume on Windows protected by BitLocker Windows
  • VM Disk
    Initialize and format a virtual disk: How to add and remove a new virtual disk from a VM on VMware Workstation Virtualization
  • image 36
    Keepalive Settings: Understanding keepalive configuration Linux
  • vmwarefrsd4
    CVE-2021-31693: VMware Tools for Windows update addresses a denial-of-service vulnerability Network | Monitoring
  • RDP Certificate Issues
    Connecting to the RDP host: Fix the Certificate could not be verified back to the root certificate Mac

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

Posted on 19/01/201909/10/2024 Christian By Christian 3 Comments on 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.

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.

5/5 - (1 vote)

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
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
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

  • Implementing DHCP Server
    Comprehensive Guide to Install DHCP Server on Windows Server Windows Server
  • image 19
    Download your MySQL database from Azure to a local PC with MySQL Workbench AWS/Azure/OpenShift
  • windows 10 creators update wallpaper 1
    How to locate and edit the host file on Windows Windows Server
  • ssl 600x315 1 1
    Components needed to create a certificate signing request Windows Server
  • Banner
    Enabling and Configuring WinRM via GPO Windows
  • Database Connection Stuck on Working on it
    How to fix TeamPass stuck on working on it Network | Monitoring

More Related Articles

Implementing DHCP Server Comprehensive Guide to Install DHCP Server on Windows Server Windows Server
image 19 Download your MySQL database from Azure to a local PC with MySQL Workbench AWS/Azure/OpenShift
windows 10 creators update wallpaper 1 How to locate and edit the host file on Windows Windows Server
ssl 600x315 1 1 Components needed to create a certificate signing request Windows Server
Banner Enabling and Configuring WinRM via GPO Windows
Database Connection Stuck on Working on it How to fix TeamPass stuck on working on it Network | Monitoring

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

sysadmin top30a

  • Featured Image new
    Add Registry Keys via DISM in Windows Windows
  • Disable download in Microsoft Edge
    How to disable file download in Microsoft Edge Windows
  • winSEARCH
    Hide or Remove Search Button from Windows 10 Taskbar Windows
  • Extend C drive with additional Software
    Fix unable to Extend Volume on Windows protected by BitLocker Windows
  • VM Disk
    Initialize and format a virtual disk: How to add and remove a new virtual disk from a VM on VMware Workstation Virtualization
  • image 36
    Keepalive Settings: Understanding keepalive configuration Linux
  • vmwarefrsd4
    CVE-2021-31693: VMware Tools for Windows update addresses a denial-of-service vulnerability Network | Monitoring
  • RDP Certificate Issues
    Connecting to the RDP host: Fix the Certificate could not be verified back to the root certificate Mac

Subscribe to Blog via Email

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

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

Tags

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

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.