Implementation:0xKoda WireMCP tshark live capture
| Knowledge Sources | |
|---|---|
| Domains | Networking, Packet_Capture |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Concrete tool for capturing live network traffic to a temporary PCAP file provided by the tshark CLI, invoked via `execAsync` within WireMCP tool handlers.
Description
The tshark live capture pattern runs `tshark -i <interface> -w <tempfile> -a duration:<seconds>` to capture packets from a live network interface for a fixed duration, writing them to a temporary PCAP file. This pattern is shared by four WireMCP tools: `capture_packets`, `get_summary_stats`, `get_conversations`, and `check_threats`. Each tool captures to the same `temp_capture.pcap` filename and cleans up with `fs.unlink` after processing.
Usage
Use this pattern when you need to capture live traffic for a bounded duration before performing further analysis (packet dissection, statistics, or IP extraction).
Code Reference
Source Location
- Repository: WireMCP
- File: index.js
- Lines: L62-65 (capture_packets), L114-117 (get_summary_stats), L155-158 (get_conversations), L196-199 (check_threats)
Signature
// Invoked as execAsync with the following command template:
execAsync(`${tsharkPath} -i ${interface} -w ${tempPcap} -a duration:${duration}`, {
env: { ...process.env, PATH: `${process.env.PATH}:/usr/bin:/usr/local/bin:/opt/homebrew/bin` }
});
Import
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| tsharkPath | string | Yes | Absolute path to tshark (from findTshark) |
| interface | string | No | Network interface (default `en0`) |
| duration | number | No | Capture duration in seconds (default `5`) |
| tempPcap | string | Yes | Output file path (hardcoded `temp_capture.pcap`) |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | File | Writes `temp_capture.pcap` to the working directory |
| (resolves) | Promise | Resolves when capture duration completes |
Usage Examples
Capture Traffic for 10 Seconds
const tsharkPath = await findTshark();
const tempPcap = 'temp_capture.pcap';
// Capture on eth0 for 10 seconds
await execAsync(
`${tsharkPath} -i eth0 -w ${tempPcap} -a duration:10`,
{ env: { ...process.env, PATH: `${process.env.PATH}:/usr/bin:/usr/local/bin:/opt/homebrew/bin` } }
);
// Read the capture back for analysis
const { stdout } = await execAsync(`${tsharkPath} -r "${tempPcap}" -T json`);
// Clean up
await fs.unlink(tempPcap).catch(err => console.error(`Cleanup failed: ${err.message}`));