网络扫描工具

MCP服务器,将python-nmap库封装为MCP工具,用于网络扫描操作。

  • by daedalus
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 daedalus/mcp-server-nmap

使用说明

mcp服务器nmap

MCP服务器,它将python nmap库作为MCP工具公开,用于网络扫描操作。

这是什么?

此MCP服务器封装了python nmap库,允许AI助手通过MCP工具执行网络侦察。它提供三个扫描界面:

  1. 端口扫描器 (同步)-阻止等待完成的扫描
  2. PortScannerAsync (异步)-带回调的非阻塞扫描
  3. PortScannerYield (生成器)-发现主机时流式传输结果

先决条件

  • 扫描器 必须安装在系统上
  • Python 3.10+

安装

pip install mcp-server-nmap

mcp名称: io.github.daedalus/mcp-server-nmap

MCP服务器注册

将此添加到MCP设置文件中:

{
  "mcpServers": {
    "mcp-server-nmap": {
      "command": "mcp-server-nmap"
    }
  }
}

或者使用自定义nmap路径:

{
  "mcpServers": {
    "mcp-server-nmap": {
      "command": "mcp-server-nmap",
      "env": {
        "PATH": "/custom/path:$PATH"
      }
    }
  }
}

可用工具

初始化

工具 说明
port_scanner_init 初始化同步端口扫描程序
port_scanner_async_init 初始化异步PortScannerAsync
port_scanner_yield_init 初始化基于生成器的PortScannerYield

扫描

工具 说明
port_scanner_scan 使用nmap扫描主机(同步)
port_scanner_async_scan 扫描主机(异步、非阻塞)
port_scanner_yield_scan 使用流式结果进行扫描
port_scanner_listscan 列出主机而不进行扫描

结果与状态

工具 说明
port_scanner_all_hosts 获取所有扫描的主机
port_scanner_has_host 检查主机是否已被扫描
port_scanner_get_item 获取详细的主机扫描数据
port_scanner_scaninfo 获取扫描配置信息
port_scanner_scanstats 获取扫描统计信息
port_scanner_command_line 获取已使用的nmap命令
port_scanner_csv 获取CSV输出
port_scanner_last_output 获取原始nmap文本输出

异步控制

工具 说明
port_scanner_async_still_scanning 检查扫描是否正在进行中
port_scanner_async_stop 停止运行扫描
port_scanner_async_wait 等待扫描完成

XML解析

工具 说明
port_scanner_analyse_xml 解析现有nmap XML输出

常见扫描工作流

基本端口扫描

# Initialize scanner
port_scanner_init()

# Scan target
port_scanner_scan(hosts="192.168.1.1", ports="22,80,443", arguments="-sV")

# Get results
port_scanner_get_item(host="192.168.1.1")

服务版本检测

port_scanner_scan(hosts="scanme.nmap.org", arguments="-sV -sC")

扫描多台主机

port_scanner_scan(hosts="192.168.1.1-254", arguments="-sS -p 22")
port_scanner_all_hosts()

网络扫描

port_scanner_scan(hosts="192.168.1.0/24", arguments="-sn")
port_scanner_csv()  # Export to CSV

nmap参数参考

参数 描述
-sn Ping扫描(主机发现)
-sS TCP SYN扫描
-sT TCP连接扫描
-sU UDP扫描
-sV 服务版本检测
-sC 默认脚本
-O 操作系统检测
-p 端口范围
-oA 输出所有格式

发展

git clone https://github.com/daedalus/mcp-server-nmap.git
cd mcp-server-nmap
pip install -e ".[test]"

# run tests
pytest

# format
ruff format src/ tests/

# lint
ruff check src/ tests/

# type check
mypy src/