使用说明
Wireshark MCP服务器
一种模型上下文协议(MCP)服务器,为AI助手提供对Wireshark网络分析功能的直接访问。该工具通过安全、标准化的接口实现了人工智能网络故障排除、数据包分析和网络监控。
特性
- 实时数据包捕获:从任何网络接口实时捕获网络流量
- PCAP文件分析:使用高级过滤功能分析现有的数据包捕获文件
- 协议统计:生成全面的协议层次结构和对话统计信息
- 网络接口管理:列出可用网络接口并与之交互
- 安全控制:全面的输入验证和权限管理
- 异步操作:用于高性能分析的非阻塞操作
需求
系统要求
- Python 3.9+ 使用pip包管理器
- Wireshark/TShark 已安装并可从命令行访问
- 网络捕获权限 (请参阅下面的设置说明)
- Windows/Linux/macOS 兼容性
网络权限设置
视窗
- 在安装过程中使用WinPcap/Npcap安装Wireshark
- 以管理员身份运行或确保用户具有网络捕获权限
Linux
# Add user to wireshark group
sudo usermod -aG wireshark $USER
# Or set capabilities on dumpcap (preferred)
sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap
# Logout and login again for group changes to take effect
macOS
# Ensure user has admin privileges or use sudo for captures
# Wireshark installer typically handles permissions
安装
- 克隆或下载项目文件
- 安装Python依赖项:
pip install -r requirements.txt - 验证Wireshark安装:
tshark --version
配置
Claude桌面集成
-
找到您的Claude Desktop配置文件:
- 视窗:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- 视窗:
-
添加Wireshark MCP服务器配置:
{ "mcpServers": { "wireshark": { "command": "python", "args": ["/absolute/path/to/wireshark-mcp-server.py"], "env": { "PYTHONPATH": "/absolute/path/to/project/directory", "MCP_LOG_LEVEL": "INFO" } } } } -
重新启动克劳德桌面 加载新服务器
VS代码/光标集成
对于VS Code或Cursor,在IDE的MCP设置中配置MCP服务器,指向 wireshark-mcp-server.py 文件。
可用工具
get_network_interfaces()
列出用于数据包捕获的所有可用网络接口。
用途:
Please list the available network interfaces
capture_live_packets(interface, count, capture_filter, timeout)
从指定接口捕获实时网络数据包。
参数:
interface:网络接口名称(例如“eth0”、“Wi-Fi”)或编号(例如“1”)count:要捕获的数据包数量(默认值:50,最大值:1000)capture_filter:BPF捕获过滤器表达式(可选)timeout:捕获超时(秒)(默认值:30,最大值:60)
用途:
Capture 100 packets from interface eth0 with filter "tcp port 80"
analyze_pcap_file(filepath, display_filter, max_packets)
使用可选过滤功能分析现有的PCAP/PCAPNG文件。
参数:
filepath:PCAP/PCAPNG文件的路径display_filter:Wireshark显示过滤器表达式(可选)max_packets:要分析的最大数据包数(默认值:100,最大值:1000)
用途:
Analyze the file /path/to/capture.pcap and show only HTTP requests
get_protocol_statistics(filepath)
从捕获文件生成协议层次结构和IP会话统计信息。
参数:
filepath:PCAP/PCAPNG文件的路径
用途:
Generate protocol statistics for /path/to/capture.pcap
get_capture_file_info(filepath)
检索捕获文件的详细信息(大小、持续时间、数据包计数等)。
参数:
filepath:PCAP/PCAPNG文件的路径
用途:
Get information about the capture file /path/to/capture.pcap
筛选器示例
捕获过滤器(BPF语法)
"tcp port 80"-HTTP流量"host 192.168.1.1"-进出特定主机的流量"net 10.0.0.0/8"-特定网络上的流量"tcp and port 443"-HTTPS流量"icmp"-ICMP/ping流量
显示过滤器(Wireshark语法)
"http.request"-仅限HTTP请求"tcp.flags.syn == 1"-TCP SYN数据包"dns.flags.response == 1"-DNS响应"ip.addr == 192.168.1.1"-进出特定IP的流量"tcp.analysis.retransmission"-TCP重传
安全功能
- 输入验证:所有用户输入都根据安全模式进行验证
- 文件路径清理:解析文件路径并验证其安全性
- 资源限制:捕获持续时间、数据包计数和文件大小受到限制
- 接口验证:只接受有效的网络接口名称
- 筛选器验证:检查捕获和显示过滤器是否存在危险模式
用法示例
基本网络故障排除
AI Assistant: "I need to troubleshoot network connectivity issues"
User: "Capture 200 packets from the main network interface and look for any issues"
HTTP流量分析
AI Assistant: "Let me analyze your web traffic"
User: "Capture traffic on port 80 and 443 for 60 seconds and show me the top websites accessed"
安全调查
AI Assistant: "Analyzing suspicious network activity"
User: "Examine this PCAP file for any unusual connections or potential security threats"
性能分析
AI Assistant: "Investigating network performance issues"
User: "Generate protocol statistics from this capture file to identify bandwidth usage"
故障排除
常见问题
-
“TShark未找到”错误
- 确保Wireshark已安装
tshark在你的路径中 - 在Windows上,检查
C:\Program Files\Wireshark\tshark.exe
- 确保Wireshark已安装
-
数据包捕获权限被拒绝
- 按照上面的网络权限设置说明进行操作
- 在Linux/macOS上,您可能需要使用
sudo用于实时捕捉
-
“未安装FastMCP”错误
- 安装所需的依赖项:
pip install -r requirements.txt
- 安装所需的依赖项:
-
未找到接口
- 使用
get_network_interfaces()查看可用界面 - 接口名称因操作系统而异
- 使用
调试模式
通过设置环境变量启用调试日志记录:
export MCP_LOG_LEVEL=DEBUG
python wireshark-mcp-server.py
发展
测试服务器
# Install development dependencies
pip install -r requirements.txt
# Test the server directly
python wireshark-mcp-server.py
# Run with debug logging
MCP_LOG_LEVEL=DEBUG python wireshark-mcp-server.py
贡献
- 分叉存储库
- 创建要素分支
- 添加新功能的测试
- 提交拉取请求
许可证
本项目按原样提供,用于教育和专业用途。请确保遵守贵组织的安全和网络监控策略。
支持
对于问题和疑问:
- 检查上面的故障排除部分
- 验证Wireshark的安装和权限
- 检查项目日志以了解详细的错误消息
- 确保所有要求都已正确安装
致谢
- 基于Anthropic的模型上下文协议(MCP)构建
- 使用Wireshark网络分析工具包
- 专为安全、人工智能驱动的网络分析而设计