Skip to main content

MCP server for querying public and private IP addresses with VPN detection

Project description

IP 查询 MCP 服务

一个用于查询本机 IP 地址的 MCP 服务,支持:

  • 内网 IP 查询
  • 公网 IP 查询
  • VPN 代理检测(自动区分真实 IP 和 VPN IP)

功能特点

智能 VPN 检测

  • 同时查询国内和国际 IP 服务
  • 如果两个服务返回的 IP 不同,说明使用了 VPN
  • 自动区分真实 IP 和 VPN 代理后的 IP

快速响应

  • 并发查询多个 IP 服务
  • 返回最快响应的结果
  • 超时保护(5秒)

安装

cd python/我的IP
pip install -e .

配置 MCP

在 Kiro 的 MCP 配置文件中添加:

方式 1: 使用 Python 模块

{
  "mcpServers": {
    "ip-query": {
      "command": "python",
      "args": ["-m", "ip_query_mcp"],
      "disabled": false
    }
  }
}

方式 2: 使用 uvx(推荐)

如果发布到 PyPI 后:

{
  "mcpServers": {
    "ip-query": {
      "command": "uvx",
      "args": ["ip-query-mcp"],
      "disabled": false
    }
  }
}

可用工具

1. get_ip_info

查询完整的 IP 信息,包括内网 IP、公网 IP,并自动检测 VPN。

示例输出(未使用 VPN):

内网 IP: 192.168.1.100
公网 IP: 123.45.67.89

✓ 未检测到 VPN 代理

示例输出(使用 VPN):

内网 IP: 192.168.1.100
公网 IP: 123.45.67.89

🔒 检测到 VPN 代理:
  真实 IP: 123.45.67.89
  VPN IP: 104.28.15.200

2. get_local_ip

仅查询内网 IP 地址。

3. get_public_ip

仅查询公网 IP 地址(不区分是否使用 VPN)。

工作原理

  1. 内网 IP: 遍历所有网络接口,优先返回局域网 IP(192.168.x.x, 10.x.x.x, 172.16-31.x.x)
  2. 真实 IP: 查询国内或响应快的 IP 服务(如 ipify.org)
  3. VPN IP: 查询国际服务(如 Cloudflare CDN)
  4. VPN 检测: 比较两个服务返回的 IP,如果不同则判定为使用了 VPN

技术细节

  • 使用 netifaces 获取所有网络接口的 IP 地址
  • 使用 httpx 进行异步 HTTP 请求
  • 并发查询多个服务,返回最快的结果
  • 支持多种 IP 服务响应格式(JSON、纯文本、Cloudflare trace)
  • 完善的错误处理和超时保护

依赖

  • Python >= 3.10
  • mcp >= 1.0.0
  • httpx >= 0.27.0
  • netifaces >= 0.11.0

开发

# 安装开发依赖
pip install -e ".[dev]"

# 运行测试
pytest

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ip_query_mcp-0.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ip_query_mcp-0.1.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file ip_query_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: ip_query_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for ip_query_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ffc095d1da49efb847f4df854afad2689f58261959b73dade9f315d3e426817b
MD5 75dcc5497f6dfe5fedbaac7395c04d2b
BLAKE2b-256 447734aaa2b6b62c972849bce82ca467c991fcbebdc267af50dc91244337c6d5

See more details on using hashes here.

File details

Details for the file ip_query_mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ip_query_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for ip_query_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ec9dc7b2b8c879f3adec6b256e567c07c09b1f5edc3b02c3bb94f1dbee3fdf5
MD5 0bb532174e52eaadfacd5217fe7cb778
BLAKE2b-256 6e4d97eef2aa11b41f9c7a1ba1b7717107eac84da5166b4bd2c45cb356f6eef3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page