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: 通过创建 UDP socket 连接到外部地址获取本机网络接口 IP
  2. 真实 IP: 查询国内或响应快的 IP 服务(如 ipify.org)
  3. VPN IP: 查询国际服务(如 Cloudflare CDN)
  4. VPN 检测: 比较两个服务返回的 IP,如果不同则判定为使用了 VPN

技术细节

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

依赖

  • Python >= 3.10
  • mcp >= 1.0.0
  • httpx >= 0.27.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.0.tar.gz (5.9 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.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ip_query_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 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.0.tar.gz
Algorithm Hash digest
SHA256 8e75d7730e44be9313e7f76dc2f0e535f1f4b3c2e37446c1bc1bf4a246cb617d
MD5 19286fd761a85cd57fa15e9650768ad7
BLAKE2b-256 738d5d8c474bf354ca2019848153ff4cfebce0728fe0878087b67256c87945e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ip_query_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39648ffed0fdedd6098864eb37e66bdcc268cff71a660ec7d51f5ec1590e9186
MD5 b0edf6e02c8369c57f0485eae2fed75b
BLAKE2b-256 bef2504459239da1b6770374db8d4f93762cb808bc607cae4aa9b870242fddd2

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