Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Windows Server » Network statistics: How to save netstat command output to a text
  • Slide1 4
    How to create and configure a Shared Folder on Windows Server Windows Server
  • How to Enable or Disable Inherited Permissions for Files and Folders in Windows
    How to Enable or Disable Inherited Permissions for Files and Folders in Windows Windows
  • image 9
    Fix Error 853: The remote access connection completed, but authentication failed because the certificate that authenticates the client to the server is not valid Network | Monitoring
  • Screenshot 2020 05 14 at 19.08.33
    Backup image to TFTP server Network | Monitoring
  • Featured image 1
    How and where to find your BitLocker recovery key on Windows Security | Vulnerability Scans and Assessment
  • APACHECASS FEATURE
    How to Install and Configure Apache Cassandra on Linux Server Linux
  • Install and configure wds 1
    Install Windows Deployment Services on Windows Server 2022 Windows Server
  • screenshot 2020 04 09 at 02.57.27
    Import certificates into Trusted Root and Personal certificate store Windows Server

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.

  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on Threads (Opens in new window) Threads
  • Click to 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

  • install virtualbox on linux mint ubuntu
    How to install Windows Server 2019 on Virtualbox Windows Server
  • DC 3
    How to demote and remove a Domain Controller on Windows Servers Windows Server
  • ADaccountexpiration
    How to set an account expiration date in Active Directory Windows Server
  • Connect to FTP Server
    Secure FTP Login Issue: NAT Router Configuration for Passive Mode and Port Forwarding Windows Server
  • Windows Defender exclusion
    Mitigate Veeam Threat Hunter Service Scanning Interference Windows Server
  • Capture 37
    How to Configure Network Load Balancing on Windows Server Backup

More Related Articles

install virtualbox on linux mint ubuntu How to install Windows Server 2019 on Virtualbox Windows Server
DC 3 How to demote and remove a Domain Controller on Windows Servers Windows Server
ADaccountexpiration How to set an account expiration date in Active Directory Windows Server
Connect to FTP Server Secure FTP Login Issue: NAT Router Configuration for Passive Mode and Port Forwarding Windows Server
Windows Defender exclusion Mitigate Veeam Threat Hunter Service Scanning Interference Windows Server
Capture 37 How to Configure Network Load Balancing on Windows Server Backup

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

  • Slide1 4
    How to create and configure a Shared Folder on Windows Server Windows Server
  • How to Enable or Disable Inherited Permissions for Files and Folders in Windows
    How to Enable or Disable Inherited Permissions for Files and Folders in Windows Windows
  • image 9
    Fix Error 853: The remote access connection completed, but authentication failed because the certificate that authenticates the client to the server is not valid Network | Monitoring
  • Screenshot 2020 05 14 at 19.08.33
    Backup image to TFTP server Network | Monitoring
  • Featured image 1
    How and where to find your BitLocker recovery key on Windows Security | Vulnerability Scans and Assessment
  • APACHECASS FEATURE
    How to Install and Configure Apache Cassandra on Linux Server Linux
  • Install and configure wds 1
    Install Windows Deployment Services on Windows Server 2022 Windows Server
  • screenshot 2020 04 09 at 02.57.27
    Import certificates into Trusted Root and Personal certificate store Windows Server

Subscribe to Blog via Email

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

Join 1,841 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.