Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 37 ยท Filters and Display

Display Filter Operators and Logic

Master Wireshark display filter operators: comparisons, contains, matches regex, in sets, slices, bitwise tests, logical and/or/not, functions and common gotchas.

Basic filters answer simple questions. Real problems need combinations: "HTTP errors from this server but not from the monitoring host", "DNS answers with a short TTL", "TCP packets with SYN set but not ACK". This lesson covers the full operator set of the Wireshark display filter language, with the gotchas that cause wrong results.

Comparison operators

Operator Alias Meaning
== eq equal
!= ne not equal
> gt greater than
< lt less than
>= ge greater or equal
<= le less or equal
contains the field contains this byte sequence or string
matches ~ the field matches a regular expression (PCRE, case-insensitive with (?i))
in the field equals one of a set {1 2 3} or lies in a range {10..20}
& bitand bitwise AND, used to test bits
TEXT
frame.len >= 1500
http.host contains "example"
http.request.uri matches "\\.(jpg|png|svg)$"
tcp.port in {80 443 8080}
tcp.dstport in {1024..65535}
tcp.flags & 0x02                 SYN bit set
(tcp.flags & 0x12) == 0x02       SYN set and ACK clear (a connection attempt)

in uses spaces (not commas) between set members. Regular expressions need doubled backslashes inside a string, because the string parser consumes one level of escaping.

Logical operators

Operator Alias Meaning
&& and both conditions
|| or either condition
! not negation
^^ xor exactly one condition

Use parentheses to make precedence explicit. and binds tighter than or, so these differ:

TEXT
dns or http and ip.addr == 192.0.2.10        DNS from anyone, OR HTTP from this host
(dns or http) and ip.addr == 192.0.2.10      DNS or HTTP, only for this host

To exclude noise, negate the whole expression with parentheses:

TEXT
!(arp or icmp or dns)
not (ip.addr == 192.0.2.1 and tcp.port == 22)

Write !(ip.addr == 192.0.2.10) or, in Wireshark 4.0 and later, simply ip.addr != 192.0.2.10. In versions before 4.0, ip.addr != 192.0.2.10 meant "some ip.addr field is different", which is true for nearly every packet (the other address differs), so it removed nothing. Check your version with Help > About.

Multi-valued fields and the != puzzle

Some fields appear more than once in a packet: ip.addr (source and destination), tcp.port, and dns.qry.name in a message with several questions. A comparison on such a field asks "does any occurrence satisfy this?". That is why ip.addr == X matches both directions, and why != needed care historically. Newer versions let you be explicit with quantifiers:

TEXT
any ip.addr == 192.0.2.10          at least one occurrence equals it (same as ==)
all ip.addr != 192.0.2.10          every occurrence differs (same as ip.addr != ... in 4.x)

The stand-in below shows the two meanings on two invented packets.

Python any vs all on multi-valued fields (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Slices, bit tests and functions

You can test parts of a field with a slice field[offset:length], counting in bytes from 0:

TEXT
eth.dst[0] & 1                          multicast/broadcast destination (lowest bit of first byte)
eth.src[0:3] == 00:00:5e                an OUI (manufacturer prefix)
ip.src[0] == 10                         source in 10.0.0.0/8 (first byte)
tcp.payload[0:4] == 47:45:54:20         starts with "GET " in hex
frame[12:2] == 08:00                    EtherType IPv4 at bytes 12-13 of the frame

Functions inspect a value: len(http.host) > 40, lower(http.host) contains "login", upper(...), count(dns.qry.name) > 1, string(ip.ttl) matches "^6", abs(), max(), min(). The layer operator field#2 refers to the second occurrence of the field when headers repeat (for example ip.src#2 for the inner IP header of a tunnel). Since version 4.0 you may also use arithmetic: tcp.window_size * 2 > 65535, frame.len - 14 > 1000.

The stand-in applies slices and bit tests to raw bytes so you can see what eth.dst[0] & 1 really inspects.

Python Slices and bit tests on bytes (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Putting it together: useful filters

TEXT
(tcp.flags & 0x12) == 0x02 and not ip.dst == 192.0.2.0/24     outgoing connection attempts to outside
http.request and not http.host contains "internal.example"     web requests to other sites
dns.flags.response == 1 and dns.flags.rcode != 0               failed DNS answers
tcp.analysis.flags and !tcp.analysis.window_update             TCP problems (retransmissions, resets...)
frame.time_delta_displayed > 0.5                               gaps of more than half a second
tls.handshake.type == 1                                        TLS Client Hello

Gotchas checklist

  • Quotes: strings need double quotes; IP addresses and numbers do not.
  • Case: contains is case-sensitive; use lower() or (?i) with matches.
  • Port vs protocol: tcp.port == 80 matches by port number, http matches by dissector. They differ if HTTP runs on another port or the port carries something else.
  • Missing fields: http.host != "x" does not match packets without that field in older versions, because the field is absent. Combine with http to scope it.
  • TLS and HTTP/2: http filters see nothing inside encrypted TLS without keys.
  • Performance: very large captures with complex regexes are slow; narrow by protocol first.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which filter shows traffic to ports 80, 443 or 8080?

    A set uses curly braces with space-separated members: in {80 443 8080}.
  2. 2. What is the difference between 'dns or http and ip.addr == 192.0.2.10' and '(dns or http) and ip.addr == 192.0.2.10'?

    Operator precedence makes 'and' bind before 'or'. Parentheses change the meaning.
  3. 3. What does '(tcp.flags & 0x12) == 0x02' test for?

    0x12 masks the SYN (0x02) and ACK (0x10) bits; the result 0x02 means only SYN is set.
  4. 4. Which filter finds packets whose destination MAC is a multicast or broadcast address?

    The lowest bit of the first destination byte marks group addresses (multicast and broadcast).

Summary

  • Use ==, !=, <, >, contains, matches, in and & to compare fields; and, or, not, xor to combine.
  • and binds tighter than or: use parentheses.
  • Multi-valued fields such as ip.addr match if any occurrence matches; != behavior changed in Wireshark 4.0.
  • Slices (field[0:3]) and bit masks inspect raw bytes; functions (len, lower, count) transform values.
  • Check quotes, case and field presence when a filter shows the wrong packets.

Next: Columns, Coloring Rules and Profiles