🌐 NetMCP
专业级网络分析MCP服务器——Wireshark/TShark+Nmap+威胁情报
      ](https://ghcr.io/cortexc0de/netmcp) 
NetMCP弥合了原始网络数据和人工智能理解之间的差距。它使Claude、Cursor和任何符合MCP的客户端能够捕获数据包、扫描网络、检测威胁和提取凭据——所有这些都是通过自然语言实现的。
______________________________________________________________________
🚀 快速开始
# Install system dependencies
sudo apt-get install -y tshark nmap # Ubuntu/Debian
# brew install wireshark nmap # macOS
# Install NetMCP
pip install netmcp
# Run
netmcp就是这样。服务器启动 标准 默认情况下,传输已准备好用于任何MCP客户端。
______________________________________________________________________
✨ 特性
- 📡 数据包捕获 --实时捕获、BPF过滤、目标流量、快速捕获模式
- 🔬 深度分析 --PCAP解析、协议统计、HTTP流量分析、DNS分析、专家信息、GeoIP丰富
- 🔄 河流重建 --跟踪TCP/UDP对话,枚举流
- 📤 灵活出口 -JSON、CSV、pcap/pcanel格式转换
- 🔍 Nmap集成 --端口扫描、服务检测、操作系统指纹识别、漏洞扫描
- 🛡️ 威胁情报 --URLhaus+滥用IPDB IP信誉检查,PCAP范围内的威胁扫描
- 🔑 凭证提取 --HTTP基本、FTP、Telnet、Kerberos(哈希猫就绪)
- 🌍 GeoIP地图 --MaxMind GeoLite2用于流量分析的IP地理定位
- 🔒 5层安全 --输入验证、shell=False、速率限制、路径遍历保护、审计日志记录
- 💬 引导式工作流程 --安全审计、事件响应、故障排除、流量分析、网络基线提示
高级功能
- 🔀 PCAP差异/合并/切片 --比较捕获,通过mergecap组合文件,通过editcap提取数据包范围
- 📊 可视化 --网络对话的ASCII艺术和美人鱼序列图
- 🔓 TLS解密 --使用SSLKEYLOGFILE(NSS密钥日志格式)解密HTTPS流量
- 🎨 Wireshark配置文件 --列出配置文件,应用配置文件设置,解析颜色过滤器,使用配置文件进行捕获
- 🧬 DNS隧道检测 --分析DNS流量并标记可疑的长子域名
- 📦 并转换部分 --具有完整协议层剖析的详细单包分析
- 🏥 专家信息 --提取Wireshark的专家警告、错误和协议违规注释
______________________________________________________________________
📊 工具类别
NetMCP提供 48工具 穿过 9类,加 3资源 和 5个提示:
| 类别 | 工具 | 描述 |
|---|---|---|
| 📡 捕获与分析 | 5 | get_network_interfaces · capture_live_packets · quick_capture · save_capture_to_file · analyze_large_pcap |
| 🔬 协议分析 | 10 | analyze_pcap_file · get_protocol_statistics · get_capture_file_info · capture_targeted_traffic · analyze_http_traffic · detect_network_protocols · analyze_http_headers · geoip_lookup · analyze_dns_traffic · get_expert_info |
| 📊 网络流 | 2 | visualize_network_flows (ASCII+美人鱼)· decrypt_tls_traffic |
| 🔧 PCAP工具 | 4 | diff_pcap_files · merge_pcap_files · slice_pcap · decode_packet |
| 🔄 流 | 3 | follow_tcp_stream · follow_udp_stream · list_tcp_streams |
| 📤 出口 | 3 | export_packets_json · export_packets_csv · convert_pcap_format |
| 🔍 扫描器 | 6 | nmap_port_scan · nmap_service_detection · nmap_os_detection · nmap_vulnerability_scan · nmap_quick_scan · nmap_comprehensive_scan |
| 🛡️ 安全 | 3 | extract_credentials · check_ip_threat_intel · scan_capture_for_threats |
| 🎨 Wireshark配置文件 | 4 | list_wireshark_profiles · apply_profile_capture · get_color_filters · capture_with_profile |
📖 API完整参考,包括参数和示例: docs/API.md文件
______________________________________________________________________
🔌 运输选项
NetMCP支持所有MCP传输协议:
| 运输 | 命令 | 用例 |
|---|---|---|
| 标准 (默认) | netmcp | Claude Desktop、Cursor、本地客户端 |
| 上海证券交易所 | netmcp --transport sse | 基于Web的客户端,远程访问 |
| 可流式传输的HTTP | netmcp --transport streamable-http | 现代HTTP客户端 |
______________________________________________________________________
⚙️ 配置
克劳德桌面版
编辑您的配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 视窗:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"netmcp": {
"command": "netmcp",
"env": {
"ABUSEIPDB_API_KEY": "your_api_key_here"
}
}
}
}光标
编辑 .cursor/mcp.json 在项目根目录中:
{
"mcpServers": {
"netmcp": {
"command": "netmcp"
}
}
}风帆/VS代码
编辑 .vscode/mcp.json:
{
"servers": {
"netmcp": {
"command": "netmcp",
"env": {
"ABUSEIPDB_API_KEY": "your_api_key_here"
}
}
}
}环境变量
| 变量 | 必填 | 默认 | 描述 |
|---|---|---|---|
ABUSEIPDB_API_KEY | 没有 | - | 滥用威胁情报的IPDB API密钥。 获取免费密钥 |
NETMCP_TSHARK_PATH | 否 | 自动检测 | tshark二进制文件的自定义路径 |
NETMCP_MAX_PACKETS | 没有 | 10000 | 每次捕获操作的最大数据包数 |
NETMCP_MAX_FILE_SIZE | 没有 | 104857600 | 最大PCAP文件大小(以字节为单位)(100 MB) |
______________________________________________________________________
📋 需求
| 依赖关系 | 必需 | 安装 |
|---|---|---|
| python | 3.11+ | sudo apt install python3.11 |
| TShark | 是的 | sudo apt install tshark |
| 扫描器 | 可选 | sudo apt install nmap |
macOS
brew install wireshark nmapLinux权限
# Option 1: Set capabilities (recommended)
sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap
# Option 2: Add user to wireshark group
sudo usermod -aG wireshark $USER && newgrp wireshark______________________________________________________________________
🛡️ 安全模型
NetMCP实现 5层纵深防御:
| 层 | 机制 | 防止 |
|---|---|---|
| 1.输入验证 | 正则表达式, ipaddress Pydantic模块 | 输入格式错误,注入有效载荷 |
| 2.指挥建设 | 列出参数, shell=False 无处不在 | 命令注入、shell扩展 |
| 3.子流程执行 | 超时,仅捕获输出 | 失控进程,资源耗尽 |
| 4.文件系统 | Path.resolve(),扩展满列表,大小限制 | 路径遍历,符号链接攻击 |
| 5.费率限制 | 滑动窗口,每次操作跟踪 | 滥用、DoS攻击 |
附加保护:
- 🔒 从不自动升级权限
- 📝 所有操作审核都记录了时间戳
- 🚫 危险nmap标志被拒绝(
--script-args,--interactive等等) - ⚠️ 清除权限问题的错误消息
______________________________________________________________________
🎯 使用示例
实时数据包捕获
You: Capture 100 packets from eth0 and analyze the protocols.
Claude: [capture_live_packets(interface="eth0", packet_count=100)]
[get_protocol_statistics(filepath="capture.pcap")]
Found 8 protocols: TCP (62%), UDP (24%), DNS (8%), HTTP (4%)...安全审计
You: Perform a security audit on suspicious.pcap
Claude: 1. [get_protocol_statistics] → traffic breakdown
2. [extract_credentials] → found HTTP Basic Auth credentials
3. [scan_capture_for_threats] → 2 malicious IPs detected
4. Generated full security report with IOCsNmap漏洞扫描
You: Scan 192.168.1.100 for vulnerabilities
Claude: [nmap_quick_scan("192.168.1.100")] → ports 22, 80, 443 open
[nmap_service_detection("192.168.1.100")] → nginx 1.18.0, OpenSSH 8.2
[nmap_vulnerability_scan("192.168.1.100")] → no critical CVEs found______________________________________________________________________
🧠 MCP资源和提示
资源
| URI | 描述 |
|---|---|
netmcp://interfaces | 可用网络接口的动态列表 |
netmcp://captures | 公用目录中的可用PCAP文件 |
netmcp://system/info | 系统功能:工具版本、功能 |
提示(引导式工作流)
| 提示 | 描述 |
|---|---|
security_audit | 基于IOC提取的全面PCAP安全分析 |
network_troubleshooting | 逐步网络诊断 |
incident_response | 安全事件调查工作流程 |
traffic_analysis | 基于GeoIP映射的深度流量分析 |
network_baseline | 建立正常的交通模式 |
______________________________________________________________________
🧪 发展
# Clone and setup
git clone https://github.com/cortexc0de/netmcp.git
cd netmcp
python -m venv .venv
source .venv/bin/activate
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=netmcp --cov-report=html
# Linting
ruff check src/netmcp/ tests/
ruff format --check src/netmcp/
mypy src/netmcp/项目结构
src/netmcp/
├── server.py # FastMCP server entry point
├── core/
│ ├── security.py # 5-layer input validation + rate limiting
│ └── formatter.py # MCP response formatting
├── interfaces/
│ ├── tshark.py # TShark async CLI wrapper
│ ├── nmap.py # python-nmap wrapper
│ └── threat_intel.py # URLhaus + AbuseIPDB clients
├── tools/ # 48 MCP tools across 11 modules
├── resources/ # 3 MCP resources
└── prompts/ # 5 MCP prompts______________________________________________________________________
🤝 贡献
欢迎投稿!看 贡献.md 作为指导方针。
- 分叉存储库
- 创建要素分支(
git checkout -b feat/amazing-feature) - 运行测试(
pytest tests/ -v) - 提交拉取请求
______________________________________________________________________
📄 许可证
MIT许可证——见 许可证 了解详情。
______________________________________________________________________
🙏 致谢
- Wireshark/TShark --数据包分析工具包
- 扫描器 --网络扫描仪
- 乌尔豪斯 & 滥用IPDB --威胁情报
- 模型上下文协议 --AI工具框架
______________________________________________________________________
通过AI驱动的数据包捕获、扫描和威胁情报来改变您的网络分析。
