3 wireshark-filter - Wireshark filter syntax and reference
7 B<wireshark> [other options]
8 S<[ B<-R> "filter expression" ]>
10 B<tshark> [other options]
11 S<[ B<-R> "filter expression" ]>
15 B<Wireshark> and B<TShark> share a powerful filter engine that helps remove
16 the noise from a packet trace and lets you see only the packets that interest
17 you. If a packet meets the requirements expressed in your filter, then it
18 is displayed in the list of packets. Display filters let you compare the
19 fields within a protocol against a specific value, compare fields against
20 fields, and check the existence of specified fields or protocols.
22 Filters are also used by other features such as statistics generation and
23 packet list colorization (the latter is only available to B<Wireshark>). This
24 manual page describes their syntax. A comprehensive reference of filter fields
25 can be found within Wireshark and in the display filter reference at
26 L<http://www.wireshark.org/docs/dfref/>.
30 =head2 Check whether a field or protocol exists
32 The simplest filter allows you to check for the existence of a protocol or
33 field. If you want to see all packets which contain the IP protocol, the
34 filter would be "ip" (without the quotation marks). To see all packets
35 that contain a Token-Ring RIF field, use "tr.rif".
37 Think of a protocol or field in a filter as implicitly having the "exists"
40 =head2 Comparison operators
42 Fields can also be compared against values. The comparison operators
43 can be expressed either through English-like abbreviations or through
50 ge, >= Greater than or Equal to
51 le, <= Less than or Equal to
53 =head2 Search and match operators
55 Additional operators exist expressed only in English, not C-like syntax:
57 contains Does the protocol, field or slice contain a value
58 matches Does the protocol or text string match the given Perl
61 The "contains" operator allows a filter to search for a sequence of
62 characters, expressed as a string (quoted or unquoted), or bytes,
63 expressed as a byte array. For example, to search for a given HTTP
64 URL in a capture, the following filter can be used:
66 http contains "http://www.wireshark.org"
68 The "contains" operator cannot be used on atomic fields,
69 such as numbers or IP addresses.
71 The "matches" operator allows a filter to apply to a specified
72 Perl-compatible regular expression (PCRE). The "matches" operator is only
73 implemented for protocols and for protocol fields with a text string
74 representation. For example, to search for a given WAP WSP User-Agent,
77 wsp.user_agent matches "(?i)cldc"
79 This example shows an interesting PCRE feature: pattern match options have to
80 be specified with the B<(?>optionB<)> construct. For instance, B<(?i)> performs
81 a case-insensitive pattern match. More information on PCRE can be found in the
82 pcrepattern(3) man page (Perl Regular Expressions are explained in
83 L<http://www.perldoc.com/perl5.8.0/pod/perlre.html>).
85 Note: the "matches" operator is only available if B<Wireshark> or B<TShark>
86 have been compiled with the PCRE library. This can be checked by running:
91 or selecting the "About Wireshark" item from the "Help" menu in B<Wireshark>.
95 The filter language has the following functions:
97 upper(string-field) - converts a string field to uppercase
98 lower(string-field) - converts a string field to lowercase
100 upper() and lower() are useful for performing case-insensitive string
101 comparisons. For example:
103 upper(ncp.nds_stream_name) contains "MACRO"
104 lower(mount.dump.hostname) == "angel"
106 =head2 Protocol field types
108 Each protocol field is typed. The types are:
110 Unsigned integer (8-bit, 16-bit, 24-bit, or 32-bit)
111 Signed integer (8-bit, 16-bit, 24-bit, or 32-bit)
113 Ethernet address (6 bytes)
119 Double-precision floating point number
121 An integer may be expressed in decimal, octal, or hexadecimal notation.
122 The following three display filters are equivalent:
128 Boolean values are either true or false. In a display filter expression
129 testing the value of a Boolean field, "true" is expressed as 1 or any
130 other non-zero value, and "false" is expressed as zero. For example, a
131 token-ring packet's source route field is Boolean. To find any
132 source-routed packets, a display filter would be:
136 Non source-routed packets can be found with:
140 Ethernet addresses and byte arrays are represented by hex
141 digits. The hex digits may be separated by colons, periods, or hyphens:
143 eth.dst eq ff:ff:ff:ff:ff:ff
145 fddi.src == aa-aa-aa-aa-aa-aa
148 IPv4 addresses can be represented in either dotted decimal notation or
149 by using the hostname:
151 ip.dst eq www.mit.edu
152 ip.src == 192.168.1.1
154 IPv4 addresses can be compared with the same logical relations as numbers:
155 eq, ne, gt, ge, lt, and le. The IPv4 address is stored in host order,
156 so you do not have to worry about the endianness of an IPv4 address
157 when using it in a display filter.
159 Classless InterDomain Routing (CIDR) notation can be used to test if an
160 IPv4 address is in a certain subnet. For example, this display filter
161 will find all packets in the 129.111 Class-B network:
163 ip.addr == 129.111.0.0/16
165 Remember, the number after the slash represents the number of bits used
166 to represent the network. CIDR notation can also be used with
167 hostnames, as in this example of finding IP addresses on the same Class C
172 The CIDR notation can only be used on IP addresses or hostnames, not in
173 variable names. So, a display filter like "ip.src/24 == ip.dst/24" is
176 IPX networks are represented by unsigned 32-bit integers. Most likely
177 you will be using hexadecimal when testing IPX network values:
179 ipx.src.net == 0xc0a82c00
181 Strings are enclosed in double quotes:
183 http.request.method == "POST"
185 Inside double quotes, you may use a backslash to embed a double quote
186 or an arbitrary byte represented in either octal or hexadecimal.
188 browser.comment == "An embedded \" double-quote"
190 Use of hexadecimal to look for "HEAD":
192 http.request.method == "\x48EAD"
194 Use of octal to look for "HEAD":
196 http.request.method == "\110EAD"
198 This means that you must escape backslashes with backslashes inside
201 smb.path contains "\\\\SERVER\\SHARE"
203 looks for \\SERVER\SHARE in "smb.path".
205 =head2 The slice operator
207 You can take a slice of a field if the field is a text string or a
209 For example, you can filter on
210 the vendor portion of an ethernet address (the first three bytes) like
213 eth.src[0:3] == 00:00:83
217 http.content_type[0:4] == "text"
219 You can use the slice operator on a protocol name, too.
220 The "frame" protocol can be useful, encompassing all the data captured
221 by B<Wireshark> or B<TShark>.
223 token[0:5] ne 0.0.0.1.1
225 frame[100-199] contains "wireshark"
227 The following syntax governs slices:
229 [i:j] i = start_offset, j = length
230 [i-j] i = start_offset, j = end_offset, inclusive.
231 [i] i = start_offset, length = 1
232 [:j] start_offset = 0, length = j
233 [i:] start_offset = i, end_offset = end_of_field
235 Offsets can be negative, in which case they indicate the
236 offset from the B<end> of the field. The last byte of the field is at offset
237 -1, the last but one byte is at offset -2, and so on.
238 Here's how to check the last four bytes of a frame:
240 frame[-4:4] == 0.1.2.3
244 frame[-4:] == 0.1.2.3
246 You can concatenate slices using the comma operator:
248 ftp[1,3-5,9:] == 01:03:04:05:09:0a:0b
250 This concatenates offset 1, offsets 3-5, and offset 9 to the end of the ftp
253 =head2 Type conversions
255 If a field is a text string or a byte array, it can be expressed in whichever
256 way is most convenient.
258 So, for instance, the following filters are equivalent:
260 http.request.method == "GET"
261 http.request.method == 47.45.54
263 A range can also be expressed in either way:
268 =head2 Bit field operations
270 It is also possible to define tests with bit field operations. Currently the
271 following bit field operation is supported:
273 bitwise_and, & Bitwise AND
275 The bitwise AND operation allows testing to see if one or more bits are set.
276 Bitwise AND operates on integer protocol fields and slices.
278 When testing for TCP SYN packets, you can write:
282 That expression will match all packets that contain a "tcp.flags" field
283 with the 0x02 bit, i.e. the SYN bit, set.
285 Similarly, filtering for all WSP GET and extended GET methods is achieved with:
289 When using slices, the bit mask must be specified as a byte string, and it must
290 have the same number of bytes as the slice itself, as in:
294 =head2 Logical expressions
296 Tests can be combined using logical expressions.
297 These too are expressible in C-like syntax or with English-like
304 Expressions can be grouped by parentheses as well. The following are
305 all valid display filter expressions:
307 tcp.port == 80 and ip.src == 192.168.2.1
309 http and frame[100-199] contains "wireshark"
310 (ipx.src.net == 0xbad && ipx.src.node == 0.0.0.0.0.1) || ip
312 Remember that whenever a protocol or field name occurs in an expression, the
313 "exists" operator is implicitly called. The "exists" operator has the highest
314 priority. This means that the first filter expression must be read as "show me
315 the packets for which tcp.port exists and equals 80, and ip.src exists and
316 equals 192.168.2.1". The second filter expression means "show me the packets
317 where not (llc exists)", or in other words "where llc does not exist" and hence
318 will match all packets that do not contain the llc protocol.
319 The third filter expression includes the constraint that offset 199 in the
320 frame exists, in other words the length of the frame is at least 200.
322 A special caveat must be given regarding fields that occur more than
323 once per packet. "ip.addr" occurs twice per IP packet, once for the
324 source address, and once for the destination address. Likewise,
325 "tr.rif.ring" fields can occur more than once per packet. The following
326 two expressions are not equivalent:
328 ip.addr ne 192.168.4.1
329 not ip.addr eq 192.168.4.1
331 The first filter says "show me packets where an ip.addr exists that
332 does not equal 192.168.4.1". That is, as long as one ip.addr in the
333 packet does not equal 192.168.4.1, the packet passes the display
334 filter. The other ip.addr could equal 192.168.4.1 and the packet would
336 The second filter says "don't show me any packets that have an
337 ip.addr field equal to 192.168.4.1". If one ip.addr is 192.168.4.1,
338 the packet does not pass. If B<neither> ip.addr field is 192.168.4.1,
339 then the packet is displayed.
341 It is easy to think of the 'ne' and 'eq' operators as having an implicit
342 "exists" modifier when dealing with multiply-recurring fields. "ip.addr
343 ne 192.168.4.1" can be thought of as "there exists an ip.addr that does
344 not equal 192.168.4.1". "not ip.addr eq 192.168.4.1" can be thought of as
345 "there does not exist an ip.addr equal to 192.168.4.1".
347 Be careful with multiply-recurring fields; they can be confusing.
349 Care must also be taken when using the display filter to remove noise
350 from the packet trace. If, for example, you want to filter out all IP
351 multicast packets to address 224.1.2.3, then using:
355 may be too restrictive. Filtering with "ip.dst" selects only those
356 B<IP> packets that satisfy the rule. Any other packets, including all
357 non-IP packets, will not be displayed. To display the non-IP
358 packets as well, you can use one of the following two expressions:
360 not ip or ip.dst ne 224.1.2.3
361 not ip.addr eq 224.1.2.3
363 The first filter uses "not ip" to include all non-IP packets and then
364 lets "ip.dst ne 224.1.2.3" filter out the unwanted IP packets. The
365 second filter has already been explained above where filtering with
366 multiply occurring fields was discussed.
368 =head1 FILTER FIELD REFERENCE
370 The entire list of display filters is too large to list here. You can
371 can find references and examples at the following locations:
377 The online Display Filter Reference: L<http://www.wireshark.org/docs/dfref/>
381 I<Help:Supported Protocols> in Wireshark
385 C<tshark -G fields> on the command line
389 The Wireshark wiki: L<http://wiki.wireshark.org/DisplayFilters>
395 The B<wireshark-filters> manpage is part of the B<Wireshark> distribution.
396 The latest version of B<Wireshark> can be found at
397 L<http://www.wireshark.org>.
399 Regular expressions in the "matches" operator are provided with B<libpcre>,
400 the Perl-Compatible Regular Expressions library: see B<http://www.pcre.org/>.
402 This manpage does not describe the capture filter syntax, which is
403 different. See the manual page of pcap-filter(4) or, if that doesn't exist,
404 tcpdump(8), or, if that doesn't exist, L<http://wiki.wireshark.org/CaptureFilters>
405 for a description of capture filters.
409 wireshark(1), tshark(1), editcap(1), pcap-filter(4), tcpdump(8), pcap(3)
413 See the list of authors in the B<Wireshark> man page for a list of authors of