Netstat(网络(Network) 统计(Statistics))是一个命令行工具,用于监控和解决计算机网络问题。该工具会根据需要向您显示所有设备的连接。
使用Netstat,您可以查看所有连接及其端口和统计信息。在设置或修复连接时,此信息很有价值。本文将向您介绍Netstat命令和用于过滤有关您的连接显示的信息的主要参数。
使用Netstat命令解决网络问题
我们将在本节探讨以下主题:
- 如何使用 Netstat 命令。
- 使用(Use)netstat 参数过滤连接信息。
- 结合 Netstat 参数。
和我一起浏览上述主题,以帮助您更好地了解此工具并了解如何使用它来解决您的网络问题。
1]如何使用netstat命令
单击 开始按钮(Start button)并搜索 命令提示符(Command Prompt)。通过右键单击它并选择 以管理员身份运行(Run as administrator)选项,以提升的权限打开命令提示符(Command Prompt)。
您可以通过键入以下命令并按 ENTER打开Netstat :
netstat
如果您是网络新手,您可能不明白这些列的含义。
- Proto: 网络协议。它可以是TCP或UDP。
- 本地地址: (Local Address: )给定连接的计算机网络接口的 IP 地址和端口。
- 外部地址: (Foreign Address: )远程设备的 IP 地址和端口名称。
- State : 指示连接的状态。例如,找出活动和关闭的连接。
netstat命令显示您的 活动连接及其详细信息。但是,您会注意到外部地址列会打印 IP 地址和端口名称。
要在 IP 地址旁边显示连接的端口号而不是端口名称,请使用以下命令:
netstat -n
此外,系统可以断开或连接到网络,并且网络详细信息可以定期更改。因此(Hence),我们可以使用以下命令每隔一段时间使用此命令刷新 netstat 网络详细信息:
netstat -n 5
要停止刷新,请按 CTRL + C组合键。
注意: (NOTE: )上面命令中的 5每(5)5 秒(5 seconds. You)刷新一次命令 。 如果您希望增加或缩短时间间隔,您可以修改此值。
2]使用(Use)netstat参数过滤连接信息
该netstat
命令是一个强大的命令,可以向您显示有关设备连接的所有详细信息。让我们探索以下最常用的 netstat 参数以查找特定的网络详细信息。
- 显示活动和非活动连接(Display active and inactive connections)
显示活跃或不活跃的网络。
netstat -a
- 显示应用程序信息(Display applications information)
列出与连接关联的所有应用程序。
netstat -b
- 查看网络适配器统计信息(View network adapter stats)
显示(Show)传入和传出网络数据包的统计信息。
netstat -e
- 显示外国地址的完全限定域名 (FQDNS)(Display foreign addresses’ fully qualified domain name (FQDNS))
如果您不想看到端口号或名称,以下 netstat 参数将显示您的外国地址的完全限定域名。
netstat -f
- 显示端口号而不是名称(Show port numbers instead of names)
将外部地址端口名称更改为端口号。
netstat -n
- 显示进程 ID(Display the process ID)
与它类似 ,它为每个连接的进程 ID(Process ID) ( PID )netstat,
提供了一个额外的列。
netstat -o
- 按协议过滤连接(Filter connections by protocol)
显示您指定的协议的连接 - UDP、TCP、tcpv6或 udpv6。
netstat -p udp
注意:(NOTE:)您应该将udp
部分更改为要查看其连接的协议。
显示(Show)连接及其侦听和绑定的非侦听端口。
netstat -q
- 按协议分组统计(Group stats by protocol)
(Categorize)按可用协议(UDP、TCP、ICMP、IPv4和IPv6 )对网络进行(IPv6)分类。
netstat -s
- 显示路由表(Display routing table)
显示当前网络的路由表。它列出了到目的地的每条路线和系统上可用的矩阵。类似于 route print
命令。
netstat -r
- 显示卸载状态连接(Display offload state connections)
显示当前连接的连接卸载状态列表。
netstat -t
- 请参阅 NetworkDirect 连接(See NetworkDirect connections)
显示(Shows)所有NetworkDirect连接。
netstat -x
- 显示连接模板(Display connection Templates)
显示您的网络的TCP连接模板。
netstat -y
3]结合Netstat参数
您可以进一步过滤Netstat参数,以任何您想要的方式向您显示有关您的连接的信息。从上述命令中,您只需添加第二个参数即可显示组合视图。
例如,您可以结合 -s
和 -e
参数来查看每个协议的统计信息。这样,你可以结合其他参数来得到你想要的结果。
混合多个Netstat参数时,不需要包含两个破折号 (-)。您可以使用一个破折号 (-) 并附加参数字母而无需第二个。
例如,不要键入以下命令:
netstat -s -e
你可以把它写成:
netstat - se
如果您忘记了参数,一个快速记住它们的方法是请 netstat 帮忙。只需运行以下命令:
网络统计/?
要随时停止 netstat 查询过程,请按CTRL + C组合键。
How to use the Netstat command to troubleshoot network issues
Netstat (Network Statistics) is a command-line tool used for monitoring and troubleshooting computer network issues. This tool shows you all your device’s connections in as much detail as you need.
With Netstat, you can view all your connections and their ports and stats. This information is valuable when setting up or fixing your connectivity. This article will introduce you to the Netstat command and the main parameters for filtering information displayed about your connections.
Using Netstat command to troubleshoot network issues
We’ll explore the following topics in this section:
- How to use the Netstat command.
- Use netstat parameters to filter connection information.
- Combining Netstat parameters.
Join me as we take a go through the above topics to help you better understand this tool and learn how to use it to troubleshoot your network issues.
1] How to use the netstat command
Click on the Start button and search for Command Prompt. Open Command Prompt with elevated privileges by right-clicking on it and selecting the Run as administrator option.
You can open Netstat by typing the following command and pressing ENTER:
netstat
If you’re new to networking, you may not understand what the columns mean.
- Proto: The network protocol. It could be either TCP or UDP.
- Local Address: The IP addresses and ports of your computer’s network interfaces for the given connections.
- Foreign Address: The IP addresses and port names of the remote devices.
- State: Indicates the state of the connection. For example, find out active and closed connections.
The netstat command shows you your active connections and their details. However, you’d notice that the foreign address column prints the IP address and port names.
To show the connections’ port numbers instead of the port names, next to the IP addresses, use the following command:
netstat -n
Further, the system can disconnect or connect to networks, and the network details can change at intervals. Hence, we can use the following command to refresh the netstat network details at intervals using this command:
netstat -n 5
To stop the refreshing, press the CTRL + C key combination.
NOTE: The 5 in the command above refreshes the command every 5 seconds. You can modify this value if you wish to increase or shorten the time interval.
2] Use netstat parameters to filter connection information
The netstat
command is a powerful command that can show you every detail about your device’s connections. Let’s explore the following most commonly used netstat parameters to find specific network details.
- Display active and inactive connections
Show the networks that are active or inactive.
netstat -a
- Display applications information
List all applications that are associated with the connections.
netstat -b
- View network adapter stats
Show statistics on incoming and outgoing network packets.
netstat -e
- Display foreign addresses’ fully qualified domain name (FQDNS)
If you don’t want to see the port numbers or names, the following netstat parameter will show your foreign addresses’ fully qualified domain names.
netstat -f
- Show port numbers instead of names
Change the foreign address port names to port numbers.
netstat -n
Similar to netstat,
and it has an extra column for every connection’s Process ID (PID).
netstat -o
- Filter connections by protocol
Display the connections for the protocol you specify – UDP, TCP, tcpv6, or udpv6.
netstat -p udp
NOTE: You should change the udp
part to the protocol whose connections you want to view.
- View non-listening and listing port
Show connections and their listening and bound non-listening ports.
netstat -q
Categorize networks by available protocols – UDP, TCP, ICMP, IPv4, and IPv6.
netstat -s
Show the routing table of your current network. It lists every route to destination and matrix available on your system. Similar to the route print
command.
netstat -r
- Display offload state connections
Show a list of connection offload state of your current connection.
netstat -t
- See NetworkDirect connections
Shows all NetworkDirect connections.
netstat -x
- Display connection Templates
Show your networks’ TCP connections templates.
netstat -y
3] Combining Netstat parameters
You can further filter the Netstat parameters to show you information about your connections any way you want. From the above commands, you only have to add a second parameter to show a combined view.
For instance, you can combine the -s
and -e
parameters to view the statistics for every protocol. In this way, you can combine other parameters to get the results you want.
When mixing multiple Netstat parameters, you don’t need to include two dashes (-). You can use one dash (-) and append the parameter letters without a second one.
For example, instead of typing the following command:
netstat -s -e
You can write it as:
netstat - se
If you forget the parameters, a quick way to remember them is by asking netstat to help out. Simply run the following command:
netstat /?
To stop the netstat query process at any time, press the CTRL + C key combination.