Troubleshooting : Tools : Packet capture
Packet capture
Packet capture, also known as sniffing or packet analysis, records some or all of the packets seen by a network interface (that is, the network interface is used in promiscuous mode). By recording packets, you can trace connection states to the exact point at which they fail, which may help you to diagnose some types of problems that are otherwise difficult to detect.
FortiADC appliances have a built-in sniffer. Packet capture on FortiADC appliances is similar to that of FortiGate appliances. To use the built-in sniffer, connect to the CLI and enter the following command:
diagnose network sniffer packet [{any | <interface_name>} [{none | '<filter_str>'} [{1 | 2 | 3} [<packets_int>]]]]
<interface_name> is either the name of a network interface, such as port1, or enter any for all interfaces.
'<filter_str>' is the sniffer filter that specifies which protocols and port numbers that you do or do not want to capture, such as 'tcp port 80', or enter none for no filters. Filters use tcpdump syntax.
{1 | 2 | 3} is an integer indicating whether to display the network interface names, packet headers, and/or payloads for each packet that the network interface sends, receives, or sees:
1 — Display the packet capture timestamp, plus basic fields of the IP header: the source IP address, the destination IP address, protocol name, and destination port number.
Does not display all fields of the IP header; it omits:
IP version number bits
Internet header length (ihl)
type of service/differentiated services code point (tos)
explicit congestion notification
total packet or fragment length
packet ID
IP header checksum
time to live (TTL)
IP flag
fragment offset
options bits
2 — All of the output from 1, plus the packet payload in both hexadecimal and ASCII. e.g.:
3 — All of the output from 2, plus the link layer (Ethernet) header. e.g.:
<packets_int> is the number of packets the sniffer reads before stopping. Packet capture output is printed to your CLI display until you stop it by pressing Ctrl+C, or until it reaches the number of packets that you have specified to capture.
Packet capture can be very resource intensive. To minimize the performance impact on your FortiADC appliance, use packet capture only during periods of minimal traffic, with a local console CLI connection rather than a Telnet or SSH CLI connection, and be sure to stop the command when you are finished.
For example, you might capture all TCP port 443 (typically HTTPS) traffic occurring through port1, regardless of its source or destination IP address. The capture uses a high level of verbosity (indicated by 3).
A specific number of packets to capture is not specified. As a result, the packet capture continues until the administrator presses Ctrl+C. The sniffer then confirms that five packets were seen by that network interface.
(Verbose output can be very long. As a result, output shown below is truncated after only one packet.)
FortiADC# diagnose network sniffer packet port1 'tcp port 443' 3
filters=[tcp port 443]
10.651905 -> syn 761714898
0x0000 0009 0f09 0001 0009 0f89 2914 0800 4500 ..........)...E.
0x0010 003c 73d1 4000 4006 3bc6 d157 fede ac16 .<s.@.@.;..W....
0x0020 0ed8 c442 01bb 2d66 d8d2 0000 0000 a002 ...B..-f........
0x0030 16d0 4f72 0000 0204 05b4 0402 080a 03ab ..Or............
0x0040 86bb 0000 0000 0103 0303 ..........
Instead of reading packet capture output directly in your CLI display, you usually should save the output to a plain text file using your CLI client. Saving the output provides several advantages. Packets can arrive more rapidly than you may be able to read them in the buffer of your CLI display, and many protocols transfer data using encodings other than US-ASCII. It is often, but not always, preferable to analyze the output by loading it into in a network protocol analyzer application such as Wireshark (
For example, you could use PuTTY or Microsoft HyperTerminal to save the sniffer output to a file. Methods may vary. See the documentation for your CLI client.
terminal emulation software such as PuTTY
a plain text editor such as Notepad
a Perl interpreter
network protocol analyzer software such as Wireshark
To view packet capture output using PuTTY and Wireshark
1. On your management computer, start PuTTY.
2. Use PuTTY to connect to the FortiADC appliance using either a local console, SSH, or Telnet connection. For details, see the FortiADC CLI Reference.
3. Type the packet capture command, such as:
diagnose network sniffer packet port1 'tcp port 443' 3
but do not press Enter yet.
4. In the upper left corner of the window, click the PuTTY icon to open its drop-down menu, then select Change Settings.
A dialog appears where you can configure PuTTY to save output to a plain text file.
5. In the Category tree on the left, go to Session > Logging.
6. In Session logging, select Printable output.
7. In Log file name, click the Browse button, then choose a directory path and file name such as C:\Users\MyAccount\packet_capture.txt to save the packet capture to a plain text file. (You do not need to save it with the .log file extension.)
8. Click Save.
9. Press Enter to send the CLI command to the FortiADC appliance, beginning packet capture.
10. If you have not specified a number of packets to capture, when you have captured all packets that you want to analyze, press Ctrl + C to stop the capture.
11. Close the PuTTY window.
12. Open the packet capture file using a plain text editor such as Notepad.
13. Delete the first and last lines, which look like this:
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2013.07.25 11:34:40 =~=~=~=~=~=~=~=~=~=~=~=
FortiADC-2000 #
These lines are a PuTTY timestamp and a command prompt, which are not part of the packet capture. If you do not delete them, they could interfere with the script in the next step.
14. Convert the plain text file to a format recognizable by your network protocol analyzer application.
You can convert the plain text file to a format (.pcap) recognizable by Wireshark (formerly called Ethereal) using the Perl script. To download, see the Fortinet Knowledge Base article Using the FortiOS built-in packet sniffer.
The script is provided as-is, without any implied warranty or technical support, and requires that you first install a Perl module compatible with your operating system.
To use, open a command prompt, then enter a command such as the following:
Methods to open a command prompt vary by operating system.
On Windows XP, go to Start > Run and enter cmd.
On Windows 7, click the Start (Windows logo) menu to open it, then enter cmd. -in packet_capture.txt -out packet_capture.pcap
where: is the name of the conversion script; include the path relative to the current directory, which is indicated by the command prompt
packet_capture.txt is the name of the packet capture’s output file; include the directory path relative to your current directory
packet_capture.pcap is the name of the conversion script’s output file; include the directory path relative to your current directory where you want the converted output to be saved
Figure 21: Converting sniffer output to .pcap format
15. Open the converted file in your network protocol analyzer application. For further instructions, see the documentation for that application.
Figure 22: Viewing sniffer output in Wireshark
For additional information on packet capture, see the Fortinet Knowledge Base article Using the FortiOS built-in packet sniffer.