2021-10-19 23:26:37 +00:00
include::../docbook/attributes.adoc[]
2021-06-18 10:20:51 +00:00
= wireshark-filter(4)
:doctype: manpage
:stylesheet: ws.css
:linkcss:
:copycss: ../docbook/{stylesheet}
2018-08-17 18:34:57 +00:00
2021-06-18 10:20:51 +00:00
== NAME
2003-10-01 14:59:41 +00:00
2019-04-20 12:14:21 +00:00
wireshark-filter - Wireshark display filter syntax and reference
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
== SYNOPSIS
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
*wireshark* [other options]
[.nowrap]#[ *-Y* "display filter expression" | *--display-filter* "display filter expression" ]#
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
*tshark* [other options]
[.nowrap]#[ *-Y* "display filter expression" | *--display-filter* "display filter expression" ]#
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
== DESCRIPTION
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
*Wireshark* and *TShark* share a powerful filter engine that helps remove
2004-06-03 07:37:49 +00:00
the noise from a packet trace and lets you see only the packets that interest
2003-10-15 02:13:33 +00:00
you. If a packet meets the requirements expressed in your filter, then it
is displayed in the list of packets. Display filters let you compare the
fields within a protocol against a specific value, compare fields against
2004-06-03 07:37:49 +00:00
fields, and check the existence of specified fields or protocols.
2003-10-01 14:59:41 +00:00
2003-10-15 02:13:33 +00:00
Filters are also used by other features such as statistics generation and
2021-06-18 10:20:51 +00:00
packet list colorization (the latter is only available to *Wireshark*). This
2010-11-30 17:46:09 +00:00
manual page describes their syntax. A comprehensive reference of filter fields
can be found within Wireshark and in the display filter reference at
2021-06-18 10:20:51 +00:00
https://www.wireshark.org/docs/dfref/.
2003-10-15 02:13:33 +00:00
2021-06-18 10:20:51 +00:00
== FILTER SYNTAX
2003-10-15 02:13:33 +00:00
2021-06-18 10:20:51 +00:00
=== Check whether a field or protocol exists
2003-12-07 18:32:59 +00:00
2003-10-15 02:13:33 +00:00
The simplest filter allows you to check for the existence of a protocol or
2005-10-30 13:46:40 +00:00
field. If you want to see all packets which contain the IP protocol, the
filter would be "ip" (without the quotation marks). To see all packets
2003-10-15 02:13:33 +00:00
that contain a Token-Ring RIF field, use "tr.rif".
2021-10-28 04:11:47 +00:00
Whenever a protocol or field appears as the argument of a function in a filter,
an exists operator for that protocol or field implicitly appears.
=== Values and operators
Each field has a value, and that value can be used in operations with
comparable values (which may be literals, other fields, or function results).
The value of a field is not necessarily what appears in the *Wireshark*
display or *TShark* output. For example, a protocol is semantically
equivalent to the sequence of bytes that it spans, not its displayed text
in the protocol tree.
2003-12-07 18:32:59 +00:00
2021-06-18 10:20:51 +00:00
=== Comparison operators
2003-12-07 18:32:59 +00:00
2021-10-28 04:11:47 +00:00
The comparison operators can be expressed either through English-like
abbreviations or through C-like symbols:
2003-10-15 02:13:33 +00:00
eq, == Equal
2004-06-03 07:37:49 +00:00
ne, != Not Equal
gt, > Greater Than
2003-10-15 02:13:33 +00:00
lt, < Less Than
ge, >= Greater than or Equal to
le, <= Less than or Equal to
2021-10-28 04:11:47 +00:00
The ordering depends on the value type in the usual way (e.g., lexicographic
for strings and arithmetic for integers.) A field may appear more than once
2021-12-31 01:05:56 +00:00
in a given frame. In that case equality can be strict (all fields must match
the condition) or not (any field must match the condition). The inequality is
the logical negation of equality. The following table contains all equality
operators, their aliases and meaning:
eq, any_eq, == Any field must be equal
ne, all_ne, != All fields must be not equal
all_eq, === All fields must be equal
any_ne, !== Any fields must be not equal
2022-04-19 23:04:05 +00:00
The operators "any" or "all" can be used with any comparison operator to make
the test match any or all fields:
all tcp.port > 1024
any ip.addr != 1.1.1.1
The "any" and "all" modifiers take precedence over comparison operators such
as "===" and "any_eq".
2021-06-18 10:20:51 +00:00
=== Search and match operators
2003-12-07 18:32:59 +00:00
2005-10-31 03:45:11 +00:00
Additional operators exist expressed only in English, not C-like syntax:
2003-12-07 18:32:59 +00:00
2017-01-22 12:20:56 +00:00
contains Does the protocol, field or slice contain a value
2021-10-28 04:11:47 +00:00
matches, ~ Does the string match the given case-insensitive
Perl-compatible regular expression
2003-12-07 18:32:59 +00:00
2004-06-03 07:37:49 +00:00
The "contains" operator allows a filter to search for a sequence of
2021-10-28 04:11:47 +00:00
characters, expressed as a string, or bytes, expressed as a byte array.
The type of the left hand side of the "contains" operator must be comparable to
that of the right hand side after any implicit or explicit conversions.
For example, to search for a given HTTP
2003-12-07 18:32:59 +00:00
URL in a capture, the following filter can be used:
2014-09-17 00:08:53 +00:00
http contains "https://www.wireshark.org"
2004-06-03 07:37:49 +00:00
The "contains" operator cannot be used on atomic fields,
such as numbers or IP addresses.
2003-12-07 18:32:59 +00:00
2021-10-28 04:11:47 +00:00
The "matches" or "~" operator allows a filter to apply to a specified
2022-06-08 10:30:03 +00:00
Perl-compatible regular expression (PCRE2). The regular expression must
2021-10-28 04:11:47 +00:00
be a double quoted string. The left hand side of the "matches" operator
must be a string, which can be a non-stringlike field implicitly or
explicitly converted to a string. Matches are case-insensitive by default.
For example, to search for a given WAP WSP User-Agent, you can write:
2003-10-15 02:13:33 +00:00
2021-06-25 19:37:57 +00:00
wsp.header.user_agent matches "cldc"
2003-12-07 18:32:59 +00:00
2017-06-21 21:34:30 +00:00
This would match "cldc", "CLDC", "cLdC" or any other combination of upper
and lower case letters.
You can force case sensitivity using
2021-06-25 19:37:57 +00:00
wsp.header.user_agent matches "(?-i)cldc"
2017-06-21 21:34:30 +00:00
2022-06-08 10:30:03 +00:00
This is an example of PCRE2's *(?*+option+*)* construct. *(?-i)* performs a
2017-06-21 21:34:30 +00:00
case-sensitive pattern match but other options can be specified as well. More
2021-06-07 03:45:14 +00:00
information can be found in the
2022-06-08 10:30:03 +00:00
pcre2pattern(3)|https://www.pcre.org/current/doc/html/pcre2pattern.html man page.
2003-12-08 22:24:36 +00:00
2021-06-18 10:20:51 +00:00
=== Functions
2006-05-02 14:26:17 +00:00
The filter language has the following functions:
upper(string-field) - converts a string field to uppercase
lower(string-field) - converts a string field to lowercase
2018-04-25 10:09:15 +00:00
len(field) - returns the byte length of a string or bytes field
count(field) - returns the number of field occurrences in a frame
2019-01-06 09:34:32 +00:00
string(field) - converts a non-string field to string
2022-04-13 13:07:01 +00:00
max(f1,...,fn) - return the maximum value
min(f1,...,fn) - return the minimum value
2022-04-13 14:30:36 +00:00
abs(field) - return the absolute value of numeric fields
2006-05-02 14:26:17 +00:00
upper() and lower() are useful for performing case-insensitive string
comparisons. For example:
upper(ncp.nds_stream_name) contains "MACRO"
lower(mount.dump.hostname) == "angel"
2019-01-06 09:34:32 +00:00
string() converts a field value to a string, suitable for use with operators like
"matches" or "contains". Integer fields are converted to their decimal representation.
It can be used with IP/Ethernet addresses (as well as others), but not with string or
byte fields. For example:
string(frame.number) matches "[13579]$"
gives you all the odd packets.
2022-04-13 13:07:01 +00:00
max() and min() take any number of arguments and returns one value, respectively
the largest/smallest. The arguments must all have the same type.
2021-06-18 10:20:51 +00:00
=== Protocol field types
2003-10-15 02:13:33 +00:00
2004-06-03 07:37:49 +00:00
Each protocol field is typed. The types are:
2022-06-21 21:31:17 +00:00
// `tshark -G ftypes | sed -e 's/.*\t/ /' | sort -f -u`, then fix up by hand
2003-10-15 02:13:33 +00:00
2022-06-21 21:31:17 +00:00
ASN.1 object identifier, plain or relative
AX.25 address
2003-10-15 02:13:33 +00:00
Boolean
2022-06-21 21:31:17 +00:00
Byte sequence
2011-12-27 20:35:41 +00:00
Character string
2022-06-21 21:31:17 +00:00
Character, 1 byte
2011-12-27 20:35:41 +00:00
Date and time
Ethernet or other MAC address
EUI64 address
2022-06-21 21:31:17 +00:00
Fibre Channel WWN
Floating point, single or double precision
2011-12-27 20:35:41 +00:00
Frame number
Globally Unique Identifier
2022-06-21 21:31:17 +00:00
IEEE-11073 floating point, 16 or 32 bits
2003-10-15 02:13:33 +00:00
IPv4 address
IPv6 address
IPX network number
2011-12-27 20:35:41 +00:00
Label
2022-06-21 21:31:17 +00:00
OSI System-ID
2011-12-27 20:35:41 +00:00
Protocol
Signed integer, 1, 2, 3, 4, or 8 bytes
Time offset
Unsigned integer, 1, 2, 3, 4, or 8 bytes
2022-06-21 21:31:17 +00:00
VINES address
2003-10-15 02:13:33 +00:00
2022-02-23 17:02:53 +00:00
An integer may be expressed in decimal, octal, hexadecimal or binary notation,
2022-06-21 11:51:01 +00:00
or as a C-style character constant. The following seven display filters
2016-09-19 01:48:50 +00:00
are equivalent:
2003-10-15 02:13:33 +00:00
2021-06-25 19:37:57 +00:00
frame.len > 10
frame.len > 012
frame.len > 0xa
2022-02-23 17:02:53 +00:00
frame.len > 0b1010
2021-06-25 19:37:57 +00:00
frame.len > '\n'
frame.len > '\x0a'
frame.len > '\012'
2003-10-15 02:13:33 +00:00
Boolean values are either true or false. In a display filter expression
2022-06-25 11:54:16 +00:00
testing the value of a Boolean field, true is expressed as the word "True"
or "TRUE" (without quotes) or any non-zero number. False is expressed as
"False" or "FALSE" or the number zero. For example, a token-ring packet's
source route field is Boolean. To find any source-routed packets, a display
filter would be any of the following:
2003-10-15 02:13:33 +00:00
tr.sr == 1
2022-06-25 11:54:16 +00:00
tr.sr == True
tr.sr == TRUE
2003-10-15 02:13:33 +00:00
Non source-routed packets can be found with:
tr.sr == 0
2022-06-25 11:54:16 +00:00
tr.sr == False
tr.sr == FALSE
2003-10-15 02:13:33 +00:00
2004-06-03 07:37:49 +00:00
Ethernet addresses and byte arrays are represented by hex
2003-10-15 02:13:33 +00:00
digits. The hex digits may be separated by colons, periods, or hyphens:
2004-06-03 07:37:49 +00:00
eth.dst eq ff:ff:ff:ff:ff:ff
aim.data == 0.1.0.d
fddi.src == aa-aa-aa-aa-aa-aa
echo.data == 7a
2003-10-15 02:13:33 +00:00
2004-06-03 07:37:49 +00:00
IPv4 addresses can be represented in either dotted decimal notation or
2003-10-15 02:13:33 +00:00
by using the hostname:
ip.src == 192.168.1.1
2021-06-25 19:37:57 +00:00
ip.dst eq www.mit.edu
2003-10-15 02:13:33 +00:00
IPv4 addresses can be compared with the same logical relations as numbers:
eq, ne, gt, ge, lt, and le. The IPv4 address is stored in host order,
2004-06-03 07:37:49 +00:00
so you do not have to worry about the endianness of an IPv4 address
2003-10-15 02:13:33 +00:00
when using it in a display filter.
2021-06-29 13:20:53 +00:00
Classless Inter-Domain Routing (CIDR) notation can be used to test if an
2003-10-15 02:13:33 +00:00
IPv4 address is in a certain subnet. For example, this display filter
2021-06-29 13:20:53 +00:00
will find all packets in the 129.111 network:
2003-10-15 02:13:33 +00:00
ip.addr == 129.111.0.0/16
Remember, the number after the slash represents the number of bits used
to represent the network. CIDR notation can also be used with
2021-06-29 13:20:53 +00:00
hostnames, as in this example of finding IP addresses on the same
2021-06-25 19:37:57 +00:00
network as 'sneezy' (requires that 'sneezy' resolve to an IP address for filter to be valid):
2003-10-15 02:13:33 +00:00
ip.addr eq sneezy/24
The CIDR notation can only be used on IP addresses or hostnames, not in
variable names. So, a display filter like "ip.src/24 == ip.dst/24" is
2004-06-03 07:37:49 +00:00
not valid (yet).
2003-10-15 02:13:33 +00:00
2021-06-29 13:20:53 +00:00
Transaction and other IDs are often represented by unsigned 16 or 32 bit integers
and formatted as a hexadecimal string with "0x" prefix:
2003-10-15 02:13:33 +00:00
2022-06-21 11:51:01 +00:00
(dhcp.id == 0xfe089c15) || (ip.id == 0x0373)
2003-10-15 02:13:33 +00:00
2004-06-03 07:37:49 +00:00
Strings are enclosed in double quotes:
2003-10-15 02:13:33 +00:00
http.request.method == "POST"
2004-06-03 07:37:49 +00:00
Inside double quotes, you may use a backslash to embed a double quote
2003-10-15 02:13:33 +00:00
or an arbitrary byte represented in either octal or hexadecimal.
2003-12-07 18:32:59 +00:00
browser.comment == "An embedded \" double-quote"
2003-10-15 02:13:33 +00:00
Use of hexadecimal to look for "HEAD":
http.request.method == "\x48EAD"
Use of octal to look for "HEAD":
2004-06-03 07:37:49 +00:00
http.request.method == "\110EAD"
2003-10-15 02:13:33 +00:00
This means that you must escape backslashes with backslashes inside
2004-06-03 07:37:49 +00:00
double quotes.
2003-10-15 02:13:33 +00:00
smb.path contains "\\\\SERVER\\SHARE"
2021-06-07 07:32:39 +00:00
looks for \\SERVER\SHARE in "smb.path". This may be more conveniently written
as
smb.path contains r"\\SERVER\SHARE"
String literals prefixed with 'r' are called "raw strings". Such strings treat
backslash as a literal character. Double quotes may still be escaped with
backslash but note that backslashes are always preserved in the result.
2003-10-15 02:13:33 +00:00
2022-06-21 11:51:01 +00:00
The following table lists all escape sequences supported with strings
and character constants:
\' single quote
\" double quote
\\ backslash
\a audible bell
\b backspace
\f form feed
\n line feed
\r carriage return
\t horizontal tab
\v vertical tab
\NNN arbitrary octal value
\xNN arbitrary hexadecimal value
\uNNNN Unicode codepoint U+NNNN
\UNNNNNNNN Unicode codepoint U+NNNNNNNN
Date and time values can be given in ISO 8601 format or using a legacy
month-year-time format:
"2020-07-04T12:34:56"
"Sep 26, 2004 23:18:04.954975"
The 'T' separator in ISO 8601 can be omitted. ISO 8601 supports timezone
designators as UTC or an offset from UTC. Legacy formats can append the
value "UTC" at the end to specify time in Coordinated Universal Time.
Otherwise date and time values are interpreted as local time.
2021-06-18 10:20:51 +00:00
=== The slice operator
2003-12-07 18:32:59 +00:00
2004-06-03 07:37:49 +00:00
You can take a slice of a field if the field is a text string or a
2013-06-07 17:06:27 +00:00
byte array.
2004-06-03 07:37:49 +00:00
For example, you can filter on
2003-10-15 02:13:33 +00:00
the vendor portion of an ethernet address (the first three bytes) like
this:
eth.src[0:3] == 00:00:83
2004-06-03 07:37:49 +00:00
Another example is:
2003-10-15 02:13:33 +00:00
2004-06-03 07:37:49 +00:00
http.content_type[0:4] == "text"
2003-10-15 02:13:33 +00:00
2004-06-03 07:37:49 +00:00
You can use the slice operator on a protocol name, too.
The "frame" protocol can be useful, encompassing all the data captured
2021-06-18 10:20:51 +00:00
by *Wireshark* or *TShark*.
2003-10-15 02:13:33 +00:00
token[0:5] ne 0.0.0.1.1
2004-06-03 07:37:49 +00:00
llc[0] eq aa
2006-05-31 19:12:15 +00:00
frame[100-199] contains "wireshark"
2003-10-15 02:13:33 +00:00
The following syntax governs slices:
2004-06-03 07:37:49 +00:00
[i:j] i = start_offset, j = length
[i-j] i = start_offset, j = end_offset, inclusive.
[i] i = start_offset, length = 1
[:j] start_offset = 0, length = j
[i:] start_offset = i, end_offset = end_of_field
2003-10-15 02:13:33 +00:00
2004-06-03 07:37:49 +00:00
Offsets can be negative, in which case they indicate the
2021-06-18 10:20:51 +00:00
offset from the *end* of the field. The last byte of the field is at offset
2004-06-03 07:37:49 +00:00
-1, the last but one byte is at offset -2, and so on.
Here's how to check the last four bytes of a frame:
2003-10-15 02:13:33 +00:00
frame[-4:4] == 0.1.2.3
or
frame[-4:] == 0.1.2.3
2021-10-28 04:11:47 +00:00
A slice can always be compared against either a string or a byte sequence.
2012-02-29 05:58:45 +00:00
Slices can be combined. You can concatenate them using the comma operator:
2004-06-03 07:37:49 +00:00
ftp[1,3-5,9:] == 01:03:04:05:09:0a:0b
This concatenates offset 1, offsets 3-5, and offset 9 to the end of the ftp
data.
2022-04-09 22:03:40 +00:00
=== The layer operator
A field can be restricted to a certain layer in the protocol stack using the
layer operator (#), followed by a decimal number:
ip.addr#2 == 192.168.30.40
2022-06-08 00:01:36 +00:00
matches only the inner (second) layer in the packet.
Layers use simple stacking semantics and protocol layers are counted sequentially starting from 1.
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".
2022-04-09 22:03:40 +00:00
2022-06-08 00:01:36 +00:00
For more complicated ranges the same syntax used with slices is valid:
2022-04-09 22:03:40 +00:00
tcp.port#[2-4]
means layers number 2, 3 or 4 inclusive. The hash symbol is required to
distinguish a layer range from a slice.
2021-06-18 10:20:51 +00:00
=== The membership operator
2015-08-19 03:03:41 +00:00
A field may be checked for matches against a set of values simply with the
membership operator. For instance, you may find traffic on common HTTP/HTTPS
ports with the following filter:
2021-10-28 04:11:47 +00:00
tcp.port in {80,443,8080}
2015-08-19 03:03:41 +00:00
as opposed to the more verbose:
tcp.port == 80 or tcp.port == 443 or tcp.port == 8080
2018-04-14 16:07:22 +00:00
To find HTTP requests using the HEAD or GET methods:
2021-10-28 04:11:47 +00:00
http.request.method in {"HEAD", "GET"}
2018-04-14 16:07:22 +00:00
The set of values can also contain ranges:
2021-10-28 04:11:47 +00:00
tcp.port in {443, 4430..4434}
ip.addr in {10.0.0.5 .. 10.0.0.9, 192.168.1.1..192.168.1.9}
2018-04-14 16:07:22 +00:00
frame.time_delta in {10 .. 10.5}
2021-10-28 04:11:47 +00:00
=== Implicit type conversions
2004-06-03 07:37:49 +00:00
2021-10-28 04:11:47 +00:00
Fields which are sequences of bytes, including protocols, are implicitly
converted to strings for comparisons against (double quoted) literal strings
and raw strings.
2004-06-03 07:37:49 +00:00
So, for instance, the following filters are equivalent:
2021-10-28 04:11:47 +00:00
tcp.payload contains "GET"
tcp.payload contains 47.45.54
2004-06-03 07:37:49 +00:00
2021-10-28 04:11:47 +00:00
As noted above, a slice can also be compared in either way:
2003-10-15 02:13:33 +00:00
2004-06-03 07:37:49 +00:00
frame[60:2] gt 50.51
frame[60:2] gt "PQ"
2003-10-15 02:13:33 +00:00
2021-10-28 04:11:47 +00:00
The inverse does not occur; stringlike fields are not implicitly converted to
byte arrays. (Some operators allow stringlike fields to be compared with
unquoted literals, which are then treated as strings; this is deprecated in
general and specifically disallowed by the "matches" operator.
Literal strings should be double quoted for clarity.)
A hex integer that is 0xff or less (which means it fits inside one byte)
can be implicitly converted to a byte string. This is not allowed for
hex integers greater than one byte, because then one would need to specify
the endianness of the multi-byte integer. Also, this is not allowed for
decimal or octal numbers, since they would be confused with the hex numbers
that make up byte string literals. Nevertheless, single-byte hex integers
can be convenient:
frame[4] == 0xff
frame[1:4] contains 0x02
2022-03-31 19:10:50 +00:00
=== Bitwise operators
2004-03-24 00:38:34 +00:00
2022-03-31 19:10:50 +00:00
It is also possible to define tests with bitwise operations. Currently the
following bitwise operator is supported:
2004-03-24 00:38:34 +00:00
bitwise_and, & Bitwise AND
2022-02-25 19:37:53 +00:00
The bitwise AND operation allows masking bits and testing to see if one or
more bits are set. Bitwise AND operates on integer protocol fields and slices.
2004-03-24 00:38:34 +00:00
2004-06-03 07:37:49 +00:00
When testing for TCP SYN packets, you can write:
2004-03-24 00:38:34 +00:00
tcp.flags & 0x02
2005-04-10 08:28:08 +00:00
That expression will match all packets that contain a "tcp.flags" field
with the 0x02 bit, i.e. the SYN bit, set.
2022-03-31 19:10:50 +00:00
To match locally administered unicast ethernet addresses you can use:
2004-03-24 00:38:34 +00:00
2022-03-31 19:10:50 +00:00
eth.addr[0] & 0x0f == 2
2004-03-24 00:38:34 +00:00
2004-06-03 07:37:49 +00:00
When using slices, the bit mask must be specified as a byte string, and it must
2004-03-24 00:38:34 +00:00
have the same number of bytes as the slice itself, as in:
ip[42:2] & 40:ff
2022-03-31 19:10:50 +00:00
=== Arithmetic operators
2022-04-04 15:52:11 +00:00
Arithmetic expressions are supported with the usual operators:
2022-03-31 19:10:50 +00:00
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo (integer remainder)
For example it is possible to filter for UDP destination ports greater or
equal by one to the source port with the expression:
udp.dstport >= udp.srcport + 1
2022-04-04 15:52:11 +00:00
It is possible to group arithmetic expressions using curly brackets (parenthesis
will not work for this):
tcp.dstport >= 4 * {tcp.srcport + 3}
Do not confuse this usage of curly brackets with set membership.
An unfortunate quirk in the filter syntax is that the subtraction operator
must be preceded by a space character, so "A-B" must be written as "A -B"
or "A - B".
2022-06-08 00:01:36 +00:00
2022-03-31 19:10:50 +00:00
=== Protocol field references
A variable using a sigil with the form ${some.proto.field} is called a field
reference. A field reference is a field value read from the currently
selected frame in the GUI. This is useful to build dynamic filters such as,
frames since the last five minutes to the selected frame:
frame.time_relative >= ${frame.time_relative} - 300
Field references share a similar notation to macros but are distinct
syntactical elements in the filter language.
2021-06-18 10:20:51 +00:00
=== Logical expressions
2003-12-07 18:32:59 +00:00
2013-06-07 17:06:27 +00:00
Tests can be combined using logical expressions.
2010-11-09 03:20:15 +00:00
These too are expressible in C-like syntax or with English-like
2022-04-03 16:57:23 +00:00
abbreviations. The following table lists the logical operators from
highest to lowest precedence:
2003-10-15 02:13:33 +00:00
2022-04-03 16:57:23 +00:00
not, ! Logical NOT (right-associative)
and, && Logical AND (left-associative)
or, || Logical OR (left-associative)
2003-10-15 02:13:33 +00:00
2022-04-03 16:57:23 +00:00
The evaluation is always performed left to right. Expressions can be grouped
by parentheses as well. The expression "A and B or not C or D and not E or F"
is read:
(A and B) or (not C) or (D and (not E)) or F
It's usually better to be explicit about grouping using parenthesis.
The following are all valid display filter expressions:
2003-10-15 02:13:33 +00:00
tcp.port == 80 and ip.src == 192.168.2.1
not llc
2006-05-31 19:12:15 +00:00
http and frame[100-199] contains "wireshark"
2004-06-03 07:37:49 +00:00
(ipx.src.net == 0xbad && ipx.src.node == 0.0.0.0.0.1) || ip
2003-10-15 02:13:33 +00:00
2003-12-07 18:32:59 +00:00
Remember that whenever a protocol or field name occurs in an expression, the
"exists" operator is implicitly called. The "exists" operator has the highest
priority. This means that the first filter expression must be read as "show me
the packets for which tcp.port exists and equals 80, and ip.src exists and
equals 192.168.2.1". The second filter expression means "show me the packets
2021-10-25 18:31:01 +00:00
where not exists llc", or in other words "where llc does not exist" and hence
2004-06-03 07:37:49 +00:00
will match all packets that do not contain the llc protocol.
The third filter expression includes the constraint that offset 199 in the
frame exists, in other words the length of the frame is at least 200.
2003-12-07 18:32:59 +00:00
2021-10-25 18:31:01 +00:00
Each comparison has an implicit exists test for any field value. Care must
be taken when using the display filter to remove noise from
the packet trace. If, for example, you want to filter out all IP
2004-06-03 07:37:49 +00:00
multicast packets to address 224.1.2.3, then using:
2003-10-15 02:13:33 +00:00
ip.dst ne 224.1.2.3
2021-10-25 18:31:01 +00:00
may be too restrictive. This is the same as writing:
2003-10-15 02:13:33 +00:00
2021-10-25 18:31:01 +00:00
ip.dst and ip.dst ne 224.1.2.3
2003-10-15 02:13:33 +00:00
2021-10-25 18:31:01 +00:00
The filter selects only frames that have the "ip.dst" field. Any
other frames, including all non-IP packets, will not be displayed. To
display the non-IP packets as well, you can use one of the following
two expressions:
not ip.dst or ip.dst ne 224.1.2.3
not ip.dst eq 224.1.2.3
The first filter uses "not ip.dst" to include all non-IP packets and then
2004-06-03 07:37:49 +00:00
lets "ip.dst ne 224.1.2.3" filter out the unwanted IP packets. The
2021-10-25 18:31:01 +00:00
second filter also negates the implicit existance test and so is
a shorter way to write the first.
2003-10-15 02:13:33 +00:00
2021-06-18 10:20:51 +00:00
== FILTER FIELD REFERENCE
2003-10-15 02:13:33 +00:00
2010-07-15 16:18:13 +00:00
The entire list of display filters is too large to list here. You can
can find references and examples at the following locations:
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
* The online Display Filter Reference: https://www.wireshark.org/docs/dfref/
2010-07-15 16:18:13 +00:00
2021-06-18 10:20:51 +00:00
* __View:Internals:Supported Protocols__ in Wireshark
2010-07-15 16:18:13 +00:00
2021-06-18 10:20:51 +00:00
* `tshark -G fields` on the command line
2010-07-15 16:18:13 +00:00
2021-06-18 10:20:51 +00:00
* The Wireshark wiki: https://gitlab.com/wireshark/wireshark/-/wikis/DisplayFilters
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
== NOTES
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
The *xref:wireshark-filter.html[wireshark-filter](4)* manpage is part of the *Wireshark* distribution.
The latest version of *Wireshark* can be found at
https://www.wireshark.org.
2003-10-01 14:59:41 +00:00
2022-06-08 15:40:54 +00:00
Regular expressions in the "matches" operator are provided by the PCRE2 library.
2021-11-20 16:46:50 +00:00
See https://www.pcre.org/ for more information.
2003-12-07 18:32:59 +00:00
2003-10-01 14:59:41 +00:00
This manpage does not describe the capture filter syntax, which is
2021-06-18 10:20:51 +00:00
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,
xref:https://www.tcpdump.org/manpages/tcpdump.1.html[tcpdump](8), or, if that doesn't exist, https://gitlab.com/wireshark/wireshark/-/wikis/CaptureFilters
2010-04-09 02:09:10 +00:00
for a description of capture filters.
2003-10-01 14:59:41 +00:00
2019-04-20 12:14:21 +00:00
Display Filters are also described in the User's Guide:
2021-06-18 10:20:51 +00:00
https://www.wireshark.org/docs/wsug_html_chunked/ChWorkBuildDisplayFilterSection.html
2019-04-20 12:14:21 +00:00
2021-06-18 10:20:51 +00:00
== SEE ALSO
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
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
2012-02-03 09:07:24 +00:00
doesn't exist.
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
== AUTHORS
2003-10-01 14:59:41 +00:00
2021-06-18 10:20:51 +00:00
See the list of authors in the *Wireshark* man page for a list of authors of
2003-10-01 14:59:41 +00:00
that code.