Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use TShark to capture a bounded sample of traffic, save it to a file, and extract only the fields or statistics your script needs. First choose an authorized interface and a narrow capture filter; then analyze the saved file with a display filter. This keeps collection and analysis separate, makes results easier to review, and avoids relying on verbose terminal output.

Choose what to measure before capturing

A packet capture is useful only if its scope matches the question. Before writing a script, decide:

  • Purpose: investigate a connection, count traffic, identify protocols or endpoints, or inspect selected decoded fields.
  • Capture point: the host and interface where the relevant packets are visible.
  • Scope: the permitted host, port, protocol and time window.
  • Output: a capture file for later analysis, parsed fields, counts, or a combination.
  • Storage and retention: where files go, who can read them, and when they are deleted.

Capture only traffic you are authorized to inspect. A capture sees traffic visible at the selected interface and capture point; it does not automatically expose all traffic on a switched network.

Check TShark, the interface and permissions

TShark is Wireshark’s terminal-oriented tool for live capture and offline analysis. Check the installed release and local help because options can differ between versions. The current online manual may describe features not present in an older installation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
  1. Confirm the command: run tshark --version and tshark -h.
  2. List interfaces: run tshark -D. The interface identifier or name you use must match an available interface on that host.
  3. Check capture access: try a short authorized capture. Live capture requires sufficient privileges, configured differently by operating system. Give the capture process only the permissions it needs; avoid running an entire long-lived monitoring script as administrator or root. See the Wireshark User’s Guide and Wireshark capture-privileges guidance.
  4. Check the destination: make sure the script can write to the intended directory and that storage and retention are bounded.

If you cannot capture, verify the interface and the host’s capture-permission setup before broadening privileges.

Capture a bounded sample and analyze it offline

For repeatable checks, capturing to a file first is often simpler than trying to parse live, human-formatted packet details. The following shell example captures for 30 seconds and then extracts selected fields from packets in the saved file. Replace eth0 with an interface shown by tshark -D, and adjust the filter and output path to your authorized scope.

#!/bin/sh
set -eu

capture=sample.pcapng
fields=traffic.tsv

# Capture only TCP traffic on port 443 for a bounded interval.
tshark -i eth0 -f 'tcp port 443' -a duration:30 -w "$capture"

# Read the capture and emit selected decoded fields.
tshark -r "$capture" -Y 'tcp' -T fields 
  -e frame.time -e ip.src -e ip.dst -e tcp.dstport > "$fields"

printf 'Capture saved to %s; selected fields saved to %sn' "$capture" "$fields"

The example uses -f for a capture filter and -Y for a display filter. These are different expression languages, not interchangeable spellings. Capture filters are applied during collection and are generally more efficient; display filters select decoded packets during analysis. TShark’s manual notes that display filters can be specified during capture or when reading a capture file, but using a display filter on busy live traffic can increase packet-loss risk. Prefer a narrow capture filter, or save and analyze afterward when that suits the task. Confirm that the filter syntax and stop condition work with your installed TShark and platform. See the TShark manual.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

-T fields produces structured, selected output that is easier to process than verbose packet descriptions. Choose fields appropriate to the traffic and protocol; a requested field may be absent for packets that do not contain it. For packet or byte totals and interval statistics, consult the installed manual’s statistics options and verify the exact output format before having a downstream script depend on it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Turn capture results into a script result

A useful automation result is specific and testable: for example, “the capture contained packets matching this scope,” “these source and destination addresses appeared,” or “the packet and byte totals changed during the interval.” Keep the capture artifact when a result needs review; parse only the fields needed for the report.

  • Check exit status: use shell error handling such as set -e, or explicitly inspect each command’s return code in another language.
  • Check packet count: a successful command that captured zero packets is not proof that the network is healthy. It may indicate the wrong interface, a filter mismatch, an unsuitable time window, or inadequate capture permissions.
  • Validate output: confirm expected columns and types before parsing. Do not assume every packet has every requested field.
  • Keep diagnostics useful: send status and errors to standard error or a log, and write machine-readable results separately from human messages.
  • Bound the job: use a duration or another locally supported stop condition and apply a retention policy to capture files.

Capture files contain packet data and may include identifiers or, depending on protocol and encryption, payload content. Restrict file access and sharing, and retain traces only as long as the diagnostic requires.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Choose the right command-line or GUI tool

Tool or approach Best fit Trade-off
TShark Scripted live capture, offline decoding, selected fields and statistics. Requires familiarity with filters, field names and local-version options.
dumpcap Capture-focused collection, including writing pcapng files for later analysis. Use TShark or Wireshark afterward when you need decoded fields or interactive inspection.
tcpdump Common lightweight command-line capture, including remote or headless scenarios described in Wireshark’s guide. For Wireshark protocol dissection or field-oriented output, a later analysis step may be needed.
Wireshark GUI Interactive follow-up on a saved capture, useful for exploring packets and filters. Less suited than a command-line pipeline to unattended, repeatable script output.

For command-line scripts that need decoded packet fields or statistics, TShark is a natural starting point. For a robust workflow, capture with an appropriate command-line tool and inspect the resulting file with TShark or the Wireshark GUI.

Troubleshoot common capture problems

No interfaces appear, or capture is denied

Run tshark -D on the machine doing the capture. Confirm that the intended interface exists and that the user or capture process has the operating-system-specific permissions required. Grant only the needed capture access rather than elevating the whole scheduled script.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The capture file is empty or contains no matching packets

Check the interface, time window, capture filter and permissions. Verify that the traffic actually traverses the capture point. Test the filter against a short, authorized sample and compare with a broader filter only when permitted and necessary.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

The script cannot parse the output

Use -T fields with explicitly named -e fields rather than parsing verbose display text. Confirm that the fields exist in the installed version and apply to the packet types in the capture. Handle missing values and check the command’s exit status.

Live capture appears to miss packets

A busy live capture with display filtering can add processing work and increase packet-loss risk. Apply a narrow capture filter with -f, reduce unnecessary output, or capture to a file and filter afterward. This does not guarantee zero loss; actual behavior depends on the host, interface, workload and capture setup.

An option in an online example is rejected

Use tshark -h and the manual installed with your release to confirm supported stop conditions, statistics options and field names. Online documentation can reflect a different release than the one on the host.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your automation goal is a website screenshot rather than packet inspection, ScreenshotNeo is a separate website screenshot API and MCP server; it does not replace TShark or capture network packets. One GET request can return an image or PDF, for example:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners are accepted and removed before the shot, along with supported consent platforms, newsletter popups and chat widgets. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the page verdict and billing status. Its MCP server offers screenshot and page-information tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up free for ScreenshotNeo.

Frequently Asked Questions

Can a packet capture show every device’s traffic on my Wi-Fi or office network?

No. It shows traffic visible at the capture interface and location, subject to the network setup and your authorization.

Should I use a capture filter or a display filter in a script?

Use a capture filter with -f to limit collection; use a display filter with -Y to select decoded packets during analysis. The syntaxes differ.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does TShark require administrator or root access?

Live capture requires sufficient privileges, but the setup is operating-system-specific. Configure limited capture permissions rather than running an entire long-lived script with elevated privileges.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.