다음을 통해 공유


NetStatTool Technology Sample

Introduces developers to the NetStatTool network information tool.

This sample demonstrates NetStatTool, which is a tool that displays statistical information about network traffic. Depending on the arguments supplied at the command line, NetStatTool collects and displays information about network connections, listening ports, and packets sent and received by the local computer. The tool uses classes in the System.Net and System.Net.NetworkInformation namespaces to gather and display information about network protocols and current TCP/IP network connections.

The following describes the command line options of NetStatTool:

NETSTATTOOL [-?] [-a] [-e] [-n] [-s] [-p protocol] [interval]

(default) Displays open connection information.

-? Displays this help message.

-e Displays NIC statistics. May be combined with -s.

-s Displays per-protocol statistics. By default, statistics are shown for TCP. The -p and -a options may be used to specify other protocols to display.

-p protocol Display information for the protocol specified. May be any of: IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6TCP. Connections can only be shown for TCP, UDP, TCPv6, or UDPv6.

-a Display information for all protocols.

-n Displays addresses and port numbers in numerical form.

Interval Redisplays selected statistics, pausing interval seconds between each display. Press CTRL+C to stop.

For information about using the samples, see the following topics:

To build the sample using the Command Prompt

  1. Navigate to the language subdirectory (CS or VB) of the NetworkInformation\NetStatTool directory, using the command prompt. For information about required settings and the SDK Command Prompt, see How to: Set Sample Settings.

  2. Type msbuild.exe NetStatTool<lang>.sln at the command line, where <lang> is either CS or VB.

To build the sample using Visual Studio

  1. Open Windows Explorer and navigate to the language subdirectory (CS or VB) of the NetworkInformation\NetStatTool directory.

  2. Double-click the icon for the NetStat<Lang>.sln file to open the file in Visual Studio, where <lang> is either CS or VB.

  3. In the Build menu, click Build Solution. The NetStatTool.exe application is created in the Bin\Debug subdirectory.

To run the sample

  1. In the Command Prompt window, navigate to the directory that contains the built executable file.

  2. Type NetStatTool.exe at the command line, with optional arguments, using the syntax described in the Remarks section.

    NoteNote

    The NetStatTool sample is a console application. You must launch and run it in a Command Prompt window to view its output.

Remarks

The NetStatTool tool takes optional arguments using the following syntax:

NetStatTool [-a] [-e] [-n] [-o] [-s] [-p proto] [interval]

The following table describes the behavior associated with each argument.

  • -a
    Displays all connections and all listening ports.
  • -e
    Displays Ethernet statistics. This option can be combined with the -s option.
  • -n
    Displays addresses and ports numerically, rather than by name.
  • -p proto
    Shows the connections for the protocol specified by proto (protocol). Proto can be any of the following values: IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6.
  • -s
    Displays statistics protocol by protocol. The default behavior displays statistics for the following protocols: IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6. Use this option with the -p option to specify a subset of the default.
  • interval
    The number of seconds that the NetStatTool application pauses before redisplaying the selected information. If you supply a value for this argument, you can stop redisplaying the statistics by pressing CTRL+C. If this argument is omitted, the tool displays the selected information once.

See Also

Reference

Dns
IcmpV4Statistics
IcmpV6Statistics
IPEndPoint
IPGlobalProperties
NetworkInterface
System.Net.NetworkInformation
System.Net.Sockets
TcpConnectionInformation
TcpState
TcpStatistics
UdpStatistics