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.2.tar.gz (6.5 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.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ip_query_mcp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 69580cfe8c2d577ed1daa1c4ec9033e41e361170679f47081094a6ca5b8a09e4
MD5 8868aefe63cb9c17151a759048ffd49d
BLAKE2b-256 52241f112dc51c5defa1f32c712b67a59f1123e9795ca176f849643b002f401b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ip_query_mcp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d417e90d0cf78ff6aec72fd665638bdebe915904720c5524367776b2f7ff9938
MD5 25dca1e3ef3259496ca6b539f761ee74
BLAKE2b-256 66d4ea3a83ed2daaecbea788e65c45c8849d3a673f1e47ed7846704f5020c62c

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