Skip to content

TechDirectArchive

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

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

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

Posted on 19/01/201909/10/2024 IT Expert By IT Expert 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.

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

  • rdp
    How to fix Remote Desktop can’t connect to the remote computer for one of these reasons Windows Server
  • install ssl certificate
    Configure SSL connection for WSUS Upstream and Downstream Servers Windows Server
  • RDS Collection 1
    How to add and remove RDS Collection Windows
  • fix windows activation 0x87E10BC6 error
    Fix Error 0x87E10BC6 on a PC running Windows non-core Edition Windows
  • Create Password Policies via GPO
    How to Create a Password Policy with Group Policy Object Windows
  • MBAM Reports
    Microsoft BitLocker Administration and Monitoring Report Fields Windows Server

More Related Articles

rdp How to fix Remote Desktop can’t connect to the remote computer for one of these reasons Windows Server
install ssl certificate Configure SSL connection for WSUS Upstream and Downstream Servers Windows Server
RDS Collection 1 How to add and remove RDS Collection Windows
fix windows activation 0x87E10BC6 error Fix Error 0x87E10BC6 on a PC running Windows non-core Edition Windows
Create Password Policies via GPO How to Create a Password Policy with Group Policy Object Windows
MBAM Reports Microsoft BitLocker Administration and Monitoring Report Fields Windows Server

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

  • image 19
    Download your MySQL database from Azure to a local PC with MySQL Workbench AWS/Azure/OpenShift
  • Trellix EPO And Syslog Integration
    Integrate Trellix ePolicy Orchestrator with a Syslog Server Security | Vulnerability Scans and Assessment
  • VBEM Licensing And Backup Server
    How to license Veeam Enterprise Manager and Add VBR Servers Backup
  • screenshot 2020 04 22 at 23.28.23
    Remove saved RDP connections in Windows Windows
  • powershell
    How to install and uninstall PowerShell on macOS via Homebrew Mac
  • UpdateOfficeOnlineServer 1
    Perform Office Online Server Update via Windows Updates Windows Server
  • Screenshot 2022 04 13 at 21.38.35
    Check Weather Conditions via Command Line on Windows, macOS, Linux and Web Linux
  • Convert OST to PST
    How to install and work with Stellar Converter for OST Reviews

Subscribe to Blog via Email

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

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