Using nmcap to Capture Traffic
When you install Network Monitor, you also install the command-line tool called nmcap. You can use nmcap to start and stop captures, and it includes a rich set of switches to control the capture.
Tip
Due to the overhead of the GUI of Network Monitor, Microsoft does not recommend using it on production systems. Instead, Microsoft recommends using nmcap to minimize the effect on system resources.
The basic syntax to start a capture is
nmcap /network * | adapter-name /file filename.cap:size
For example, if you want to start a capture on all adapters for a system, save the capture to a file named dc1cap.cap, and limit the size to 10 MB, you can use the following command:
nmcap /network * /capture /file dc1cap.cap:10mb
The following listing shows what you see as the capture runs:
c:\>nmcap /network * /capture /file dc1cap.cap:10mb
Network Monitor Command Line Capture (nmcap) 3.4.2350.0
Saving info to: c:\\dc1cap.cap - using circular buffer of size
10.00 MB.
ATTENTION: Conversations Disabled: Some filters require
conversations and will not work correctly (see Help for details)
ATTENTION: Process Tracking Disabled: Use /CaptureProcesses to
enable (see Help for details)
Note: Process Filtering Disabled.
Exit by Ctrl+C
Capturing | Received: 12 Pending: 0 Saved: 12 Dropped: 0 |
Time: 27 seconds.
Files captured this way can be opened by typing in the name of the file (such as dc1cap.cap) at the command prompt. Because .cap is associated with Network Monitor, this launches Network Monitor and opens the capture within it. You can also open Network Monitor and browse to the capture file as shown previously.
The previous command runs the capture on all available NICs; however, you can choose just a single NIC if desired. First, you can view a list of available network cards with the /displaynetworks switch as shown in the following listing.
c:\>nmcap /displaynetworks
Network Monitor Command Line Capture (nmcap) 3.4.2350.0
0. Local Area Connection (Intel 21140-Based PCI Fast Ethernet
Adapter)
1. NDISWANBH (WAN Miniport)
If you want to run the command on only the NIC named Local Area Connection, use the number 0 with the /network switch like the following:
nmcap /network 0 /capture /file dc1cap.cap:10mb
Automatically Starting, Stopping, and Terminating nmcap
nmcap has some switches to start at a certain time, stop after a period of time, or terminate based on certain conditions. The following table shows some of the uses.