Skip to main content

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

Metadata

Release files for ip-query-mcp 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ip-query-mcp 0.1.2
File Size Uploaded
ip_query_mcp-0.1.2.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ip-query-mcp 0.1.2
File Interpreter ABI Platform
ip_query_mcp-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.5 kB

Release files / ip_query_mcp-0.1.2.tar.gz

Download URL ip_query_mcp-0.1.2.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
69580cfe8c2d577ed1daa1c4ec9033e41e361170679f47081094a6ca5b8a09e4
BLAKE2b-256 checksum
How to use checksums
52241f112dc51c5defa1f32c712b67a59f1123e9795ca176f849643b002f401b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / ip_query_mcp-0.1.2-py3-none-any.whl

Download URL ip_query_mcp-0.1.2-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d417e90d0cf78ff6aec72fd665638bdebe915904720c5524367776b2f7ff9938
BLAKE2b-256 checksum
How to use checksums
66d4ea3a83ed2daaecbea788e65c45c8849d3a673f1e47ed7846704f5020c62c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page