1 include::../attributes.adoc[]
6 :copycss: {css_dir}/{stylesheet}
10 wireshark-filter - Wireshark display filter syntax and reference
14 *wireshark* [other options]
15 [.nowrap]#[ *-Y* "display filter expression" | *--display-filter* "display filter expression" ]#
17 *tshark* [other options]
18 [.nowrap]#[ *-Y* "display filter expression" | *--display-filter* "display filter expression" ]#
22 *Wireshark* and *TShark* share a powerful filter engine that helps remove
23 the noise from a packet trace and lets you see only the packets that interest
24 you. If a packet meets the requirements expressed in your filter, then it
25 is displayed in the list of packets. Display filters let you compare the
26 fields within a protocol against a specific value, compare fields against
27 fields, and check the existence of specified fields or protocols.
29 Filters are also used by other features such as statistics generation and
30 packet list colorization (the latter is only available to *Wireshark*). This
31 manual page describes their syntax. A comprehensive reference of filter fields
32 can be found within Wireshark and in the display filter reference at
33 https://www.wireshark.org/docs/dfref/.
37 === Check whether a field or protocol exists
39 The simplest filter allows you to check for the existence of a protocol or
40 field. If you want to see all packets which contain the IP protocol, the
41 filter would be "ip" (without the quotation marks). To see all packets
42 that contain a Token-Ring RIF field, use "tr.rif".
44 Whenever a protocol or field appears as the argument of a function in a filter,
45 an exists operator for that protocol or field implicitly appears.
47 === Values and operators
49 Each field has a value, and that value can be used in operations with
50 comparable values (which may be literals, other fields, or function results).
51 The value of a field is not necessarily what appears in the *Wireshark*
52 display or *TShark* output. For example, a protocol is semantically
53 equivalent to the sequence of bytes that it spans, not its displayed text
56 === Comparison operators
58 The comparison operators can be expressed either through English-like
59 abbreviations or through C-like symbols:
65 ge, >= Greater than or Equal to
66 le, <= Less than or Equal to
68 The ordering depends on the value type in the usual way (e.g., lexicographic
69 for strings and arithmetic for integers.) A field may appear more than once
70 in a given frame. In that case equality can be strict (all fields must match
71 the condition) or not (any field must match the condition). The inequality is
72 the logical negation of equality. The following table contains all equality
73 operators, their aliases and meaning:
75 eq, any_eq, == Any field must be equal
76 ne, all_ne, != All fields must be not equal
77 all_eq, === All fields must be equal
78 any_ne, !== Any fields must be not equal
80 The operators "any" or "all" can be used with any comparison operator to make
81 the test match any or all fields:
85 any ip.addr != 1.1.1.1
87 The "any" and "all" modifiers take precedence over comparison operators such
88 as "===" and "any_eq".
90 === Search and match operators
92 Additional operators exist expressed only in English, not C-like syntax:
94 contains Does the protocol, field or slice contain a value
95 matches, ~ Does the string match the given case-insensitive
96 Perl-compatible regular expression
98 The "contains" operator allows a filter to search for a sequence of
99 characters, expressed as a string, or bytes, expressed as a byte array.
100 The type of the left hand side of the "contains" operator must be comparable to
101 that of the right hand side after any implicit or explicit conversions.
103 For example, to search for a given HTTP
104 URL in a capture, the following filter can be used:
106 http contains "https://www.wireshark.org"
108 The "contains" operator cannot be used on atomic fields,
109 such as numbers or IP addresses.
111 The "matches" or "~" operator allows a filter to apply to a specified
112 Perl-compatible regular expression (PCRE2). The regular expression must
113 be a double quoted string. The left hand side of the "matches" operator
114 must be a string, which can be a non-stringlike field implicitly or
115 explicitly converted to a string. Matches are case-insensitive by default.
116 For example, to search for a given WAP WSP User-Agent, you can write:
118 wsp.header.user_agent matches "cldc"
120 This would match "cldc", "CLDC", "cLdC" or any other combination of upper
121 and lower case letters.
123 You can force case sensitivity using
125 wsp.header.user_agent matches "(?-i)cldc"
127 This is an example of PCRE2's *(?*+option+*)* construct. *(?-i)* performs a
128 case-sensitive pattern match but other options can be specified as well. More
129 information can be found in the
130 pcre2pattern(3)|https://www.pcre.org/current/doc/html/pcre2pattern.html man page.
134 The filter language has the following functions:
136 upper(string-field) - converts a string field to uppercase
137 lower(string-field) - converts a string field to lowercase
138 len(field) - returns the byte length of a string or bytes field
139 count(field) - returns the number of field occurrences in a frame
140 string(field) - converts a non-string field to string
141 vals(field) - converts a field value to its value string
142 dec(field) - converts an unsigned integer to a decimal string
143 hex(field) - converts an unsigned integer to a hexadecimal string
144 float(field) - converts a field to single precision floating point
145 double(field) - converts a field to double precision floating point
146 max(f1,...,fn) - return the maximum value
147 min(f1,...,fn) - return the minimum value
148 abs(field) - return the absolute value of numeric fields
150 upper() and lower() are useful for performing case-insensitive string
151 comparisons. For example:
153 upper(ncp.nds_stream_name) contains "MACRO"
154 lower(mount.dump.hostname) == "angel"
156 string() converts a field value to a string, suitable for use with operators like
157 "matches" or "contains". Integer fields are converted to their decimal representation.
158 It can be used with IP/Ethernet addresses (as well as others), but not with string or
159 byte fields. For example:
161 string(frame.number) matches "[13579]$"
163 gives you all the odd packets. Note that the "matches" operator implicitly
164 converts types of their value string representation; to match against the
165 decimal representation of an integer field use string().
167 vals() converts an integer or boolean field value to a string using the
168 field's associated value string, if it has one. This produces strings
169 similar to those seen in custom columns. The resultant string can also
170 be used with other operators. E.g.:
172 vals(pfcp.msg_type) contains "Request"
174 would match all packets which have a PFCP request, even if that request is not
175 matched with a response.
177 dec() and hex() convert unsigned integer fields to decimal or hexadecimal
178 representation. Currently dec() and string() give same result for an unsigned
179 integer, but it is possible that in the future string() will use the native
182 max() and min() take any number of arguments and returns one value, respectively
183 the largest/smallest. The arguments must all have the same type.
185 There is also a set of functions to test IP addresses:
187 ip_special_name(ip) - Returns the IP special-purpose block name as a string
188 ip_special_mask(ip) - Returns the IP special-purpose block flags as a mask. The bits are:
192 S = Source, D = Destination, F = Forwardable, G = Globally-reachable, R = Reserved-by-protocol
194 ip_linklocal(ip) - true if the IPv4 or IPv6 address is link-local
195 ip_multicast(ip) - true if the IPv4 or IPv6 address is multicast
196 ip_rfc1918(ipv4) - true if the IPv4 address is private-use (from the allocation in RFC 1918)
197 ip_ula(ipv6) - true if the IPv6 address is unique-local (ULA) as in RFC 4193
201 It is possible to define display filter macros. Macro are names that are
202 replaced with the associated expression, possibly performing argument substitution.
203 Macro expansions are purely textual replacements and performed recursively before compilation.
204 They allow replacing long and often used expressions with easy to use names.
206 Macros are defined using the GUI or directly in the "dmacros" configuration
207 file. For example the definition
209 "addplusone" {$1 + $2 + 1}
211 creates a macro called `addplusone` that takes two arguments and expands to the given expression.
212 Arguments in the replacement expression are given using the dollar sign.
214 Macros are invoked like function but preceded with a dollar sign
215 (sometimes also called a sigil):
217 $addplusone(udp.src_port,udp.dst_port)
219 results in the expression
221 {udp.src_port + udp.dst_port + 1}
223 after argument substitution. There is an older alternative notation to invoke macros:
225 ${addplusone:udp.src_port;udp.dst_port}
229 ${addplusone;udp.src_port;udp.dst_port}
231 Both forms are equivalent and can be used interchangibly as a matter of
234 === Protocol field types
236 Each protocol field is typed. The types are:
237 // `tshark -G ftypes | sed -e 's/.*\t/ /' | sort -f -u`, then fix up by hand
239 ASN.1 object identifier, plain or relative
246 Ethernet or other MAC address
249 Floating point, single or double precision
251 Globally Unique Identifier
252 IEEE-11073 floating point, 16 or 32 bits
259 Signed integer, 1, 2, 3, 4, or 8 bytes
261 Unsigned integer, 1, 2, 3, 4, or 8 bytes
264 An integer may be expressed in decimal, octal, hexadecimal or binary notation,
265 or as a C-style character constant. The following seven display filters
276 Boolean values are either true or false. In a display filter expression
277 testing the value of a Boolean field, true is expressed as the word `true`
278 (case-insensitive) or any non-zero number. False is expressed as
279 `false` (case-insensitive) or the number zero. For example, a token-ring packet's
280 source route field is Boolean. To find any source-routed packets, a display
281 filter would be any of the following:
287 Non source-routed packets can be found with:
293 Ethernet addresses and byte arrays are represented by hex
294 digits. The hex digits may be separated by colons, periods, or hyphens:
296 eth.dst eq ff:ff:ff:ff:ff:ff
298 fddi.src == aa-aa-aa-aa-aa-aa
301 IPv4 addresses can be represented in either dotted decimal notation or
302 by using the hostname:
304 ip.src == 192.168.1.1
305 ip.dst eq www.mit.edu
307 IPv4 addresses can be compared with the same logical relations as numbers:
308 eq, ne, gt, ge, lt, and le. The IPv4 address is stored in host order,
309 so you do not have to worry about the endianness of an IPv4 address
310 when using it in a display filter.
312 Classless Inter-Domain Routing (CIDR) notation can be used to test if an
313 IPv4 address is in a certain subnet. For example, this display filter
314 will find all packets in the 129.111 network:
316 ip.addr == 129.111.0.0/16
318 Remember, the number after the slash represents the number of bits used
319 to represent the network. CIDR notation can also be used with
320 hostnames, as in this example of finding IP addresses on the same
321 network as 'sneezy' (requires that 'sneezy' resolve to an IP address for filter to be valid):
325 The CIDR notation can only be used on IP addresses or hostnames, not in
326 variable names. So, a display filter like "ip.src/24 == ip.dst/24" is
329 Transaction and other IDs are often represented by unsigned 16 or 32 bit integers
330 and formatted as a hexadecimal string with "0x" prefix:
332 (dhcp.id == 0xfe089c15) || (ip.id == 0x0373)
334 Strings are enclosed in double quotes:
336 http.request.method == "POST"
338 Inside double quotes, you may use a backslash to embed a double quote
339 or an arbitrary byte represented in either octal or hexadecimal.
341 browser.comment == "An embedded \" double-quote"
343 Use of hexadecimal to look for "HEAD":
345 http.request.method == "\x48EAD"
347 Use of octal to look for "HEAD":
349 http.request.method == "\110EAD"
351 This means that you must escape backslashes with backslashes inside
354 smb.path contains "\\\\SERVER\\SHARE"
356 looks for \\SERVER\SHARE in "smb.path". This may be more conveniently written
359 smb.path contains r"\\SERVER\SHARE"
361 String literals prefixed with 'r' are called "raw strings". Such strings treat
362 backslash as a literal character. Double quotes may still be escaped with
363 backslash but note that backslashes are always preserved in the result.
365 The following table lists all escape sequences supported with strings
366 and character constants:
378 \NNN arbitrary octal value
379 \xNN arbitrary hexadecimal value
380 \uNNNN Unicode codepoint U+NNNN
381 \UNNNNNNNN Unicode codepoint U+NNNNNNNN
383 Date and time values can be given in ISO 8601 format or using a legacy
384 month-year-time format:
386 "2020-07-04T12:34:56"
387 "Sep 26, 2004 23:18:04.954975"
389 The 'T' separator in ISO 8601 can be omitted. The timezone can be given
390 as "Z" or an offset from UTC.
392 When not using ISO 8601 the timezone can be given as the strings "UTC", "GMT"
393 or "UT" for UTC or also given as an offset from UTC, plus some North American and Nautical/Military
394 designations (https://man.netbsd.org/strptime.3[see the specification for %z in strptime(3)]).
395 Note that arbitrary timezone names are not supported however.
397 If the timezone is omitted then date and time values are interpreted as local time.
399 === The slice operator
401 You can take a slice of a field if the field base type is a text string or a
402 byte array (the base type of most network address fields is bytes).
403 For example, you can filter on the vendor portion of an ethernet address
404 (the first three bytes) like this:
406 eth.src[0:3] == 00:00:83
410 http.content_type[0:4] == "text"
412 You can use the slice operator on a protocol name, too.
413 The "frame" protocol can be useful, encompassing all the data captured
414 by *Wireshark* or *TShark*.
416 token[0:5] ne 0.0.0.1.1
418 frame[100-199] contains "wireshark"
420 The following syntax governs slices:
422 [i:j] i = start_offset, j = length
423 [i-j] i = start_offset, j = end_offset, inclusive.
424 [i] i = start_offset, length = 1
425 [:j] start_offset = 0, length = j
426 [i:] start_offset = i, end_offset = end_of_field
428 Slice indexes are zero-based.
429 Offsets can be negative, in which case they indicate the
430 offset from the *end* of the field. The last byte of the field is at offset
431 -1, the last but one byte is at offset -2, and so on.
432 Here's how to check the last four bytes of a frame:
434 frame[-4:4] == 0.1.2.3
438 frame[-4:] == 0.1.2.3
440 As mentioned above the slice operator can be used on string and byte fields
441 and will respectively produce string or byte slices. String slices are
442 indexed on UTF-8 codepoint boundaries (i.e: internationalized characters),
443 so the following comparison is true:
447 The example above generates an error because the compiler rejects constant
448 expressions but is otherwise syntactically correct and exemplifies the
449 behaviour of string slices.
451 To obtain a byte slice of the same string the raw (@) operator can be used:
453 @"touché"[5-6] == c3:a9
455 A slice can always be compared against either a string or a byte sequence.
457 Slices can be combined. You can concatenate them using the comma operator:
459 ftp[1,3-5,9:] == 01:03:04:05:09:0a:0b
461 This concatenates offset 1, offsets 3-5, and offset 9 to the end of the ftp
464 === The layer operator
466 A field can be restricted to a certain layer in the protocol stack using the
467 layer operator (#), followed by a decimal number:
469 ip.addr#2 == 192.168.30.40
471 matches only the inner (second) layer in the packet.
472 Layers use simple stacking semantics and protocol layers are counted sequentially starting from 1.
473 For example, in a packet that contains two IPv4 headers, the outer (first) source address can be matched with "ip.src#1" and the inner (second) source address can be matched with "ip.src#2".
475 For more complicated ranges the same syntax used with slices is valid:
479 means layers number 2, 3 or 4 inclusive. The hash symbol is required to
480 distinguish a layer range from a slice.
484 By prefixing the field name with an at sign (@) the comparison is done against
485 the raw packet data for the field.
487 A character string must be decoded from a source encoding during dissection.
488 If there are decoding errors the resulting string will usually contain
489 replacement characters:
491 [subs="replacements"]
493 browser.comment == "string is ����"
496 The at operator allows testing the raw undecoded data:
498 @browser.comment == 73:74:72:69:6e:67:20:69:73:20:aa:aa:aa:aa
500 The syntactical rules for a bytes field type apply to the second example.
502 === The membership operator
504 A field may be checked for matches against a set of values simply with the
505 membership operator. For instance, you may find traffic on common HTTP/HTTPS
506 ports with the following filter:
508 tcp.port in {80,443,8080}
510 as opposed to the more verbose:
512 tcp.port == 80 or tcp.port == 443 or tcp.port == 8080
514 To find HTTP requests using the HEAD or GET methods:
516 http.request.method in {"HEAD", "GET"}
518 The set of values can also contain ranges:
520 tcp.port in {443, 4430..4434}
521 ip.addr in {10.0.0.5 .. 10.0.0.9, 192.168.1.1..192.168.1.9}
522 frame.time_delta in {10 .. 10.5}
524 === Implicit type conversions
526 Fields which are sequences of bytes, including protocols, are implicitly
527 converted to strings for comparisons against (double quoted) literal strings
530 So, for instance, the following filters are equivalent:
532 tcp.payload contains "GET"
533 tcp.payload contains 47.45.54
535 As noted above, a slice can also be compared in either way:
540 The inverse does not occur; stringlike fields are not implicitly converted to
541 byte arrays. (Some operators allow stringlike fields to be compared with
542 unquoted literals, which are then treated as strings; this is deprecated in
543 general and specifically disallowed by the "matches" operator.
544 Literal strings should be double quoted for clarity.)
546 A hex integer that is 0xff or less (which means it fits inside one byte)
547 can be implicitly converted to a byte string. This is not allowed for
548 hex integers greater than one byte, because then one would need to specify
549 the endianness of the multi-byte integer. Also, this is not allowed for
550 decimal or octal numbers, since they would be confused with the hex numbers
551 that make up byte string literals. Nevertheless, single-byte hex integers
555 frame[1:4] contains 0x02
557 An integer or boolean field that has a value string can be compared to
558 to one of the strings that corresponds with a value.
559 As with stringlike fields and comparisons, it is possible to perform
560 the comparison with an unquoted literal, though this is deprecated and
561 will not work if the literal contains a space (as with "Modify Bearer
562 Response" above). Double quotes are recommended.
564 If there is a unique reverse mapping from the string literal into a
565 numeric value, the string is converted into that number and the
566 comparison function is applied using arithmetic rules. If the mapping
567 is not unique, then equality and inequality can be tested, but not the
570 This is in contrast to the `string()` and `vals()` function, which
571 convert the field value to a string and applies string (lexicographic)
572 comparisons, as well as work with all operators that take strings.
573 Therefore the following two filters give the same result:
575 gtpv2.message_type <= 35
576 gtpv2.message_type <= "Modify Bearer Response"
580 vals(gtpv2.message_type) <= "Modify Bearer Response"
582 matches all messages whose value string precedes "Modify Bearer Response"
583 in lexicographical order, and
585 string(gtpv2.message_type) <= "35"
587 matches all messages such that the message type comes before "35" in
588 lexicographical order, i.e. would also match "170" (the message type
589 for "Release Access Bearers Request.")
591 === Bitwise operators
593 It is also possible to define tests with bitwise operations. Currently the
594 following bitwise operator is supported:
596 bitand, bitwise_and, & Bitwise AND
598 The bitwise AND operation allows masking bits and testing to see if one or
599 more bits are set. Bitwise AND operates on integer protocol fields and slices.
601 When testing for TCP SYN packets, you can write:
605 That expression will match all packets that contain a "tcp.flags" field
606 with the 0x02 bit, i.e. the SYN bit, set.
608 To match locally administered unicast ethernet addresses you can use:
610 eth.addr[0] & 0x0f == 2
612 When using slices, the bit mask must be specified as a byte string, and it must
613 have the same number of bytes as the slice itself, as in:
617 === Arithmetic operators
619 Arithmetic expressions are supported with the usual operators:
625 % Modulo (integer remainder)
627 Arithmetic operations can be performed on numeric types. Numeric types are
628 integers, floating point numbers and date and time values.
630 Date and time values can only be multiplied by integers or floating point
631 numbers (i.e: scalars) and furthermore the scalar multiplier must appear on
632 the right-hand side of the arithmetic operation.
634 For example it is possible to filter for UDP destination ports greater or
635 equal by one to the source port with the expression:
637 udp.dstport >= udp.srcport + 1
639 It is possible to group arithmetic expressions using curly brackets (parenthesis
640 will not work for this):
642 tcp.dstport >= 4 * {tcp.srcport + 3}
644 Do not confuse this usage of curly brackets with set membership.
646 An unfortunate quirk in the filter syntax is that the subtraction operator
647 must be preceded by a space character, so "A-B" must be written as "A -B"
650 === Protocol field references
652 A variable using a sigil with the form $some.proto.field or ${some.proto.field} is called a field
653 reference. A field reference is a field value read from the currently
654 selected frame in the GUI. This is useful to build dynamic filters such as,
655 frames since the last five minutes to the selected frame:
657 frame.time_relative >= ${frame.time_relative} - 300
661 frame.time_relative >= $frame.time_relative - 300
663 Field references share a similar notation to macros but are distinct
664 syntactical elements in the filter language.
666 === Logical expressions
668 Tests can be combined using logical expressions.
669 These too are expressible in C-like syntax or with English-like
670 abbreviations. The following table lists the logical operators from
671 highest to lowest precedence:
673 not, ! Logical NOT (right-associative)
674 and, && Logical AND (left-associative)
675 xor, ^^ Logical XOR (left-associative)
676 or, || Logical OR (left-associative)
678 The evaluation is always performed left to right. Expressions can be grouped
679 by parentheses as well. The expression "A and B or not C or D and not E or F"
682 (A and B) or (not C) or (D and (not E)) or F
684 It's usually better to be explicit about grouping using parenthesis.
685 The following are all valid display filter expressions:
687 tcp.port == 80 and ip.src == 192.168.2.1
689 http and frame[100-199] contains "wireshark"
690 (ipx.src.net == 0xbad && ipx.src.node == 0.0.0.0.0.1) || ip
692 Remember that whenever a protocol or field name occurs in an expression, the
693 "exists" operator is implicitly called. The "exists" operator has the highest
694 priority. This means that the first filter expression must be read as "show me
695 the packets for which tcp.port exists and equals 80, and ip.src exists and
696 equals 192.168.2.1". The second filter expression means "show me the packets
697 where not exists llc", or in other words "where llc does not exist" and hence
698 will match all packets that do not contain the llc protocol.
699 The third filter expression includes the constraint that offset 199 in the
700 frame exists, in other words the length of the frame is at least 200.
702 Because each comparison has an implicit exists test for field values care must
703 be taken when using the display filter to remove noise from
704 the packet trace. If, for example, you want to filter out all IP
705 multicast packets to address 224.1.2.3, then using:
709 may be too restrictive. This is the same as writing:
711 ip.dst and ip.dst ne 224.1.2.3
713 The filter selects only frames that have the "ip.dst" field. Any
714 other frames, including all non-IP packets, will not be displayed. To
715 display the non-IP packets as well, you can use one of the following
718 not ip.dst or ip.dst ne 224.1.2.3
719 not ip.dst eq 224.1.2.3
721 The first filter uses "not ip.dst" to include all non-IP packets and then
722 lets "ip.dst ne 224.1.2.3" filter out the unwanted IP packets. The
723 second filter also negates the implicit existence test and so is
724 a shorter way to write the first.
726 == FILTER FIELD REFERENCE
728 The entire list of display filters is too large to list here. You can
729 can find references and examples at the following locations:
731 * The online Display Filter Reference: https://www.wireshark.org/docs/dfref/
733 * __View:Internals:Supported Protocols__ in Wireshark
735 * `tshark -G fields` on the command line
737 * The Wireshark wiki: {wireshark-wiki-url}DisplayFilters
741 The *xref:wireshark-filter.html[wireshark-filter](4)* manpage is part of the *Wireshark* distribution.
742 The latest version of *Wireshark* can be found at
743 https://www.wireshark.org.
745 Regular expressions in the "matches" operator are provided by the PCRE2 library.
746 See https://www.pcre.org/ for more information.
748 This manpage does not describe the capture filter syntax, which is
749 different. See the manual page of xref:https://www.tcpdump.org/manpages/pcap-filter.7.html[pcap-filter](7) or, if that doesn't exist,
750 xref:https://www.tcpdump.org/manpages/tcpdump.1.html[tcpdump](8), or, if that doesn't exist, {wireshark-wiki-url}CaptureFilters
751 for a description of capture filters.
753 Display Filters are also described in the link:{wireshark-users-guide-url}ChWorkBuildDisplayFilterSection.html[Wireshark User's Guide].
757 xref:wireshark.html[wireshark](1), xref:tshark.html[tshark](1), xref:editcap.html[editcap](1), xref:https://www.tcpdump.org/manpages/pcap.3pcap.html[pcap](3), xref:https://www.tcpdump.org/manpages/pcap-filter.7.html[pcap-filter](7) or xref:https://www.tcpdump.org/manpages/tcpdump.1.html[tcpdump](8) if it
762 See the list of authors in the *Wireshark* man page for a list of authors of