Web Server Windows Server

How to save netstat command output to a text

Netstat

The network statistics (netstat ) command is a networking tool used for troubleshooting and configuration, that 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. Here are some related contents: How to logoff, restart, or shutdown Windows PC or Server remotely via Command Prompt and PowerShell, Error: Telnet is not recognized as an internal or external command, 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.

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

See the image below for the syntax and text output ;) That is it :)
– See the following guides on “how to prevent a remote shutdown and restart in Windows 10, how to allow only admin users (administrators) to shut down and reboot Windows Server 2012, how to prevent users from shutting down in a Virtual Machine and Handy Command-Prompt Shutdown Commands.

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 tcpudptcpv6, or udpv6. If you use -s with -p to view statistics by protocol, you can use icmpipicmpv6, 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

I hope you found this blog post helpful. If you have any questions, please let me know in the comment session.

Subscribe
Notify of
guest
2 Comments
Inline Feedbacks
View all comments
John
John
9 months ago

Doesn’t work

2
0
Would love your thoughts, please comment.x
()
x
Kindly subscribe to TechDirectArchive
This is default text for notification bar