You can write a Wireshark display filter with an LLM faster than you can find the field in the Display Filter Reference, and the draft will usually look right. Then tshark rejects it, because the model invented http.status, or handed you a capture filter, or the filter came back through a chat window with curly quotes. The worse case is a filter that is valid and matches nothing, which looks exactly like "the traffic isn't there." An LLM Wireshark filter is a draft until tshark has parsed it and returned the frames you expected from a pcap you own.
This guide runs that loop on one small capture. Every error message and frame count below came from three tshark builds reading the same pcap on one box on December 1, 2026 (America/Denver): Wireshark 4.6.10, the current stable release, built from the official source tarball; Debian 13's packaged 4.4.19; and the 5.0.0rc1 development release. We checked syntax against the wireshark-filter man page and the Display Filter Reference. The broken filters were written for this guide to reproduce mistakes models commonly make; they are not a captured model transcript, and no model was called in the lab. tshark's output is the evidence.
Authorized captures only. Filter traffic on networks you own or are hired to assess, and keep real packet contents out of prompts. Strip addresses, hostnames, cookies and tokens before anything goes to a model.
Why this is timely: Wireshark 5.0 changes what a filter accepts
Two changes in the 5.0 development series matter for anyone pasting filters out of a chat window. The 5.0.0rc1 announcement (November 11, 2026) lists them under the changes since 4.7.2: English operator forms like and and or are now case-insensitive, and string literals can be wrapped in matching "smart" or "curly" double quotes instead of straight ones.
That is good news for copy and paste, but it is not in the stable branch. Wireshark 4.6.10 and 4.4.20 came out on November 18, 2026, and in our lab 4.6.10 and 4.4.19 still reject both. So a filter that works on a colleague's 5.0 release candidate can fail on your 4.6 install, and the error message won't mention quotes.
The 4.6.10 release is worth installing for another reason. Its release notes list 39 security advisories (wnpa-sec-2026-111 through -149), mostly dissector and file-parser crashes, and say the volume is "due to an internal review and a recent trend in AI-assisted vulnerability reports from outside researchers." Opening a pcap means parsing untrusted input, so run the current release before you open captures you didn't make.
How to test an LLM-written Wireshark display filter
Ask two questions, in order:
- Does it parse?
tshark -Y '<filter>'prints the reason when the filter is invalid, with a caret under the problem, and exited with status 4 in every one of our runs.dftest, a small tool in the Wireshark source tree, parses a filter without any capture and prints the compiled instructions. It's built with Wireshark from source; Debian 13's tshark package doesn't include it, so tshark alone is enough. - Does it match the right frames, and only those? Count the matches on a lab pcap where you already know the answer, then print the fields you care about with
-T fields.
# 1. Does it parse? (non-zero exit = invalid filter; 4 in our runs)
tshark -n -r lab.pcap -Y 'http.request and http.user_agent matches "sqlmap"' > /dev/null; echo $?
# 2. What does it match?
tshark -n -r lab.pcap -Y 'http.request and http.user_agent matches "sqlmap"' \
-T fields -e frame.number -e ip.src -e http.request.uri
A valid filter that matches nothing also exits 0. That is the case to worry about, and the reason step 2 exists.
Step 1: Build a lab pcap you own
Decide what each filter should return before you ask a model for anything. We ran Python's http.server on 127.0.0.1:8080 and 127.0.0.1:8000, a 16-line Python DNS responder on 127.0.0.1:53 that answers two names and returns NXDOMAIN for everything else, and captured the loopback interface with tcpdump. Then we sent traffic from four loopback source addresses with curl and dig:
| Client | Traffic | Expected |
|---|---|---|
127.0.0.2 (browser) | /, /robots.txt, /favicon.ico on port 8080; one DNS lookup | 2 × 200, 1 × 404 |
127.0.0.3 (scanner, user agent sqlmap/1.9.11#stable) | 8 requests such as /.env, /.git/config, /wp-login.php and /index.php?id=1' OR 1=1-- | 8 × 404 |
127.0.0.4 (API client) | /api/health and /admin on port 8000; one DNS lookup | 1 × 200, 1 × 404 |
127.0.0.5 | 5 lookups of long hex labels under exfil.lab.internal | 5 × NXDOMAIN |
The capture has 172 frames. The capture filter on tcpdump kept unrelated loopback traffic out of the file, which is worth doing on any shared machine.
The targets for the rest of the guide: 8 HTTP requests from the scanner, 10 HTTP 404 responses, and 5 NXDOMAIN responses.
Step 2: Give the model the version and real field names
A prompt that works:
Write Wireshark display filters for Wireshark 4.6 (stable, not 5.0). Use straight ASCII double quotes and lowercase
and/or. Use only these fields: http.request, http.request.uri, http.user_agent, http.response.code, dns.flags.response, dns.flags.rcode, dns.qry.name, ip.addr. Write three filters, one per line: (1) HTTP requests whose user agent mentions sqlmap, in any case; (2) HTTP 404 responses; (3) DNS responses with NXDOMAIN. No explanation.
The field list does most of the work. You can pull candidate fields from your own build in seconds. Our 4.6.10 build lists 248,493 lines in tshark -G fields; checking a handful of names the model might use takes one command:
$ tshark -G fields | cut -f3 | grep -x -E "http.status|http.response.code|http.response_for.uri|dns.rcode|dns.flags.rcode|http.request.uri"
dns.flags.rcode
http.request.uri
http.response.code
Three of the six names don't exist in 4.6.10. http.status, dns.rcode and http.response_for.uri look plausible, and that is exactly why a model reaches for them.
Step 3: An invented field name
A typical first draft for "HTTP 404 responses":
$ tshark -n -r lab.pcap -Y 'http.status == 404'
tshark: "http.status" is not a valid protocol or protocol field.
http.status == 404
^~~~~~~~~~~
Exit status 4. This is the easy failure: tshark names the bad token. The fix is the real field, http.response.code:
$ tshark -n -r lab.pcap -Y 'http.response.code == 404' -T fields -e frame.number -e ip.dst -e http.request.uri -e http.response.code
33 127.0.0.2 /favicon.ico 404
47 127.0.0.3 /admin 404
59 127.0.0.3 /.env 404
71 127.0.0.3 /.git/config 404
83 127.0.0.3 /wp-login.php 404
95 127.0.0.3 /index.php?id=1%27%20OR%201%3D1-- 404
107 127.0.0.3 /backup.zip 404
119 127.0.0.3 /phpmyadmin/ 404
131 127.0.0.3 /server-status 404
156 127.0.0.4 /admin 404
Ten frames, as expected. Note the port: the API client's 404 on port 8000 is there too. Our builds dissected port 8000 as HTTP without a Decode As rule. On ports Wireshark doesn't associate with HTTP, the same filter can return nothing until you add -d tcp.port==<port>,http.
The same thing happened with DNS. dns.rcode == 3 fails with the same "not a valid protocol or protocol field" error. The real field is dns.flags.rcode. Asking for the value by its common name fails too:
$ tshark -n -r lab.pcap -Y 'dns.flags.rcode == "NXDOMAIN"'
tshark: "NXDOMAIN" cannot be found among the possible values for dns.flags.rcode.
Wireshark's own label for rcode 3 is "No such name" (tshark -G values shows it), so dns.flags.rcode == "No such name" and dns.flags.rcode == 3 both return the 5 NXDOMAIN responses. Use the number; it survives label changes.
Step 4: Capture filter syntax in a display filter
Ask a model to "filter traffic to the scanner" and you will often get Berkeley Packet Filter (BPF) syntax, which is what tcpdump and tshark -f use at capture time:
$ tshark -n -r lab.pcap -Y 'host 127.0.0.3'
tshark: "127.0.0.3" was unexpected in this context.
host 127.0.0.3
^~~~~~~~~
Note: That read filter code looks like a valid capture filter;
maybe you mixed them up?
tshark spots this one for you. port 53 fails the same way. The display filter equivalents are ip.addr == 127.0.0.3 (96 frames here) and udp.port == 53. The Wireshark wiki's DisplayFilters page opens on this exact point ("Display filter is not a capture filter"), and CaptureFilters covers the BPF side. Display filter syntax itself is in the user guide. Tell the model which one you want, by name, every time.
Step 5: Smart quotes and uppercase operators
The filter below is correct in every way except the quote characters. It is what a filter looks like after a trip through a chat app, a ticket or a notes tool that "fixes" quotes:
$ tshark -n -r lab.pcap -Y 'http.user_agent contains “sqlmap”'
tshark: Non-printable ASCII characters may only appear inside double-quotes.
http.user_agent contains “sqlmap”
^
Here is how the same set of filters behaved on the three builds:
| Filter | 4.4.19 | 4.6.10 | 5.0.0rc1 |
|---|---|---|---|
http.user_agent contains “sqlmap” (curly quotes) | rejected | rejected | 8 frames |
http.request.method == "GET" AND http.response.code == 404 | rejected: "AND" was unexpected | rejected | 0 frames |
http.user_agent contains 'sqlmap' (single quotes) | rejected: too long to be a valid character constant | rejected | rejected |
tcp.port in {8000 8080} and http.request (no comma) | rejected: "8080" was unexpected | rejected | rejected |
tcp.port in {8000, 8080} and http.request | 13 frames | 13 frames | 13 frames |
The curly-quote and uppercase rows are the Wireshark 5.0 change in action. Until 5.0 is your stable install, ask for straight quotes and lowercase operators, and normalize anything you paste. Single quotes are character constants in display filters, not strings, on every version. Set members need commas; the man page's examples are http.request.method in {"HEAD", "GET"} and tcp.port in {443, 4430..4434}.
The uppercase AND row has a second problem that 5.0 does not fix, which is the next step.
Step 6: The quiet failures that match nothing
These filters all parse, exit 0, and are wrong.
A request field and a response field in one filter. "GET requests that got a 404" sounds like one condition, so a model writes:
$ tshark -n -r lab.pcap -Y 'http.request.method == "GET" and http.response.code == 404' | wc -l
0
Zero, on every version. Display filters test one frame at a time, and the request and the response are different frames. The response frame does carry the request URI in our builds, so http.response.code == 404 and http.request.uri contains "/admin" returns the two 404 responses for /admin. For the requests themselves, filter on request fields only.
Case-sensitive contains. http.user_agent contains "SQLMAP" returns 0 frames. contains compares bytes. matches is a regular expression match and, per the man page, case-insensitive by default, so http.user_agent matches "SQLMAP" returns all 8 scanner requests. lower(http.user_agent) contains "sqlmap" also works. A model that adds (?i) to a matches pattern isn't wrong, just redundant.
Searching for a decoded string in an encoded field. http.request.uri contains "OR 1=1" returns 0. The URI field holds what was on the wire, id=1%27%20OR%201%3D1--. contains "%20OR%201%3D1" matches.
A bare string after or. http.request.uri contains "/.env" or "/.git" is rejected (/.git is neither a field nor a protocol name), which is the friendly version of this bug. Use a set, http.request.uri in {"/.env", "/.git/config"}, or a regex, http.request.uri matches "^/\\.(env|git)".
Regex escapes. dns.qry.name matches "^[0-9a-f]{16,}\." is rejected with \. is not a valid character escape sequence. Inside a double-quoted string, the backslash needs its own backslash ("^[0-9a-f]{16,}\\."), or use a raw string, r"^[0-9a-f]{16,}\.". Both return 10 frames: the five long-label queries and their five responses.
Frames, not events. That last result is a reminder that counts are frame counts. Ten frames is five lookups. Add dns.flags.response == 1 (or http.request for HTTP) when you want one side of the exchange.
The filters that passed
$ tshark -n -r lab.pcap -Y 'http.request and http.user_agent matches "sqlmap"' -T fields -e frame.number -e ip.src -e http.request.uri
43 127.0.0.3 /admin
55 127.0.0.3 /.env
67 127.0.0.3 /.git/config
79 127.0.0.3 /wp-login.php
91 127.0.0.3 /index.php?id=1%27%20OR%201%3D1--
103 127.0.0.3 /backup.zip
115 127.0.0.3 /phpmyadmin/
127 127.0.0.3 /server-status
$ tshark -n -r lab.pcap -Y 'dns.flags.response == 1 and dns.flags.rcode == 3' -T fields -e ip.dst -e dns.qry.name -e dns.flags.rcode
127.0.0.5 6a6f686e2e646f65.exfil.lab.internal 3
127.0.0.5 70617373776f7264.exfil.lab.internal 3
127.0.0.5 3132333435363738.exfil.lab.internal 3
127.0.0.5 6c61622d6461746131.exfil.lab.internal 3
127.0.0.5 6c61622d6461746132.exfil.lab.internal 3
Eight requests, ten 404 responses (Step 3) and five NXDOMAIN responses: all three targets from Step 1, on 4.4.19, 4.6.10 and 5.0.0rc1.
Common mistakes in LLM Wireshark filters
| Mistake | What tshark said | Fix |
|---|---|---|
Invented field (http.status, dns.rcode) | is not a valid protocol or protocol field | Check names with tshark -G fields or the Display Filter Reference |
BPF in -Y (host, port) | was unexpected in this context plus the capture filter note | ip.addr ==, udp.port ==; keep BPF for -f |
Curly quotes, uppercase AND on 4.x | Non-printable ASCII characters..., "AND" was unexpected | Straight quotes, lowercase operators, or Wireshark 5.0 |
| Single-quoted string | too long to be a valid character constant | Double quotes |
| Set without commas | "8080" was unexpected | {8000, 8080} |
| Request and response fields together | No error, 0 frames | One side per filter |
contains with the wrong case | No error, 0 frames | matches or lower() |
| Decoded text in an encoded URI | No error, 0 frames | Match the encoded form |
| Single backslash in a regex | not a valid character escape sequence | \\. or r"..." |
A small validator for the loop
tshark's exit status makes the parse check easy to automate. This script rejects invalid filters and filters whose frame count falls outside what you expect from your lab pcap:
#!/bin/bash
# usage: check_filter.sh <pcap> '<display filter>' <min> <max>
pcap=$1 filter=$2 min=$3 max=$4
err=$(tshark -n -r "$pcap" -Y "$filter" 2>&1 >/dev/null)
if [ $? -ne 0 ]; then echo "REJECTED: $(printf '%s' "$err" | head -n 1)"; exit 2; fi
n=$(tshark -n -r "$pcap" -Y "$filter" | wc -l)
if [ "$n" -lt "$min" ] || [ "$n" -gt "$max" ]; then echo "WRONG COUNT: $n frames (expected $min-$max)"; exit 1; fi
echo "OK: $n frames"
Run against 4.6.10 with the scanner target of exactly 8 frames:
$ ./check_filter.sh lab.pcap 'http.user_agent contains “sqlmap”' 8 8
REJECTED: tshark: Non-printable ASCII characters may only appear inside double-quotes.
$ ./check_filter.sh lab.pcap 'http.request.method == "GET" and http.response.code == 404' 8 8
WRONG COUNT: 0 frames (expected 8-8)
$ ./check_filter.sh lab.pcap 'http.request and http.user_agent matches "sqlmap"' 8 8
OK: 8 frames
To close the loop with a model, send the REJECTED or WRONG COUNT line back and ask for a corrected filter. This sketch does that with the OpenAI Python SDK and RedRouter's https://redrouter.org/v1 base URL from the quickstart. We did not run it against the API for this post; the tshark half is the script above.
import os, subprocess
from openai import OpenAI
client = OpenAI(base_url="https://redrouter.org/v1", api_key=os.environ["REDROUTER_API_KEY"])
messages = [{"role": "user", "content": open("prompt.txt").read()}] # Step 2 prompt, one filter
for attempt in range(4):
reply = client.chat.completions.create(model="glm-5.3-flash-red", messages=messages)
flt = reply.choices[0].message.content.strip().strip("`").strip()
flt = flt.replace("\u201c", '"').replace("\u201d", '"') # normalize curly quotes for 4.x
check = subprocess.run(["./check_filter.sh", "lab.pcap", flt, "8", "8"], capture_output=True, text=True)
print(flt, "->", check.stdout.strip())
if check.returncode == 0:
break
messages += [{"role": "assistant", "content": flt},
{"role": "user", "content": check.stdout.strip() + "\nReturn one corrected Wireshark 4.6 display filter only."}]
Stop the automation at "the count matches the lab." Whether the filter means what you think on real traffic is a judgment, so keep a person on that part.
What to send the model, and what not to
- Send: your Wireshark version, the goal in plain words, the field names you confirmed with
tshark -G fields, the exact tshark error with its caret line, and the frame count you expected versus what you got. - Scrub: real addresses, hostnames, URIs with tokens, cookies, credentials and anything that identifies users. Reproduce the pattern in a lab, as we did, and send that.
- Don't send: production pcaps or full packet dumps. A model doesn't need packet bytes to fix a filter.
- Check retention. On RedRouter, account zero data retention is an opt-in setting, off by default. The data handling docs explain what is stored and the controls, and what RedRouter keeps covers the defaults in plain terms.
Display filters find frames in a capture you already have. If you want detections that run on live traffic, see Suricata rules with an LLM for signatures and Zeek scripts with an LLM for stateful scripts that write logs; both fail in different ways from a one-line filter. For active probing rather than passive analysis, Nmap NSE scripts with an LLM uses the same draft-then-verify loop. And if your pcaps come from CTF forensics challenges, the LLM CTF workflow covers where filters fit.
Choosing a model for Wireshark filters
Any model that follows "one filter, no explanation" and can take a few rounds of tshark errors will do. On RedRouter, GLM 5.3 Flash Red (glm-5.3-flash-red) is $0.25 per 1M input tokens, $0.13 per 1M cached input tokens and $1.00 per 1M output tokens. red-cyber-1 (Beta), the featured model for authorized penetration testing and red-team work, is $0.28 / $0.13 / $1.10 per 1M tokens. Current rates for every model are in the models docs, and plans are on /pricing.
Filter prompts describe attack traffic plainly: scanner user agents, SQL injection strings, credential file paths, exfiltration patterns. RedRouter is built for that kind of authorized security work.
FAQ
Can I write a Wireshark display filter with an LLM?
Yes, as a first draft. In our lab, drafts with invented fields, capture filter syntax, curly quotes and mixed request and response fields all failed, either loudly with exit status 4 or quietly with 0 frames. Corrected filters returned the expected 8, 10 and 5 frames on three Wireshark versions.
How do I test an LLM Wireshark filter?
Run it with tshark -n -r lab.pcap -Y '<filter>' on a pcap where you know the answer. Exit status 4 means the filter is invalid. Exit 0 with the wrong frame count means it's valid and wrong. If you built Wireshark from source, dftest '<filter>' checks the syntax without a capture.
Why does tshark say a field "is not a valid protocol or protocol field"?
The field name doesn't exist in your build. Models often guess names such as http.status or dns.rcode; the real fields are http.response.code and dns.flags.rcode. Check with tshark -G fields or the Display Filter Reference.
Why does my AI pcap display filter fail with smart quotes?
Wireshark 4.6 and earlier accept only straight double quotes around strings, and report "Non-printable ASCII characters may only appear inside double-quotes." The 5.0 development release accepts matching curly quotes. Replace “ ” with " before running the filter.
What is the difference between a capture filter and a display filter?
Capture filters use BPF syntax (host 10.0.0.5, port 53) and decide what gets recorded, with tcpdump or tshark -f. Display filters use Wireshark field syntax (ip.addr == 10.0.0.5, udp.port == 53) and decide what you see, with tshark -Y or the Wireshark filter bar.
Is it safe to paste packet captures into an LLM?
Not raw production captures unless your terms allow it. Send field names, error messages and scrubbed lab examples instead. On RedRouter, account zero data retention is opt-in and off by default; see the data handling docs.
Sources
- Wireshark documentation, checked December 1, 2026: wireshark-filter(4) man page, User's Guide: Building display filter expressions, Display Filter Reference (HTTP, DNS), tshark man page, dftest man page.
- Wireshark project: News (4.6.10 and 4.4.20, November 18, 2026; 5.0.0rc1, November 11, 2026), Wireshark 4.6.10 release notes, Download.
- Wireshark wiki: DisplayFilters, CaptureFilters.
- Lab outputs: tshark 4.6.10 and 5.0.0rc1 built from the official source tarballs (SHA-256 checked against the published SIGNATURES files), and Debian 13's tshark 4.4.19, run against a generated loopback pcap on December 1, 2026.
- OpenAI Python SDK.
- RedRouter Docs: Quickstart, Models and pricing, Data handling. Checked December 1, 2026.