IP (Plain Text)
返回访客公网出口 IP(纯文本),适用于自动化脚本与网络通道检测。
Returns the visitor public egress IP in plain text, designed for automation and network path checks.
一、功能说明 Overview
- 返回访客公网 IP(Public Egress IP)。
- 响应格式为纯文本(
text/plain),不包含 JSON 包装。
- 支持 IPv4 IPv6。
- Dual Stack 指同一入口可同时响应 IPv4 与 IPv6,请求最终返回值取决于客户端实际连通通道。
- Returns the visitor public IP address.
- Response format is plain text (
text/plain) without JSON envelope.
- Supports IPv4 and IPv6.
- Dual Stack means one endpoint serves both IPv4 and IPv6; output depends on the client's active network path.
三、使用示例 Examples
curl 示例
curl ipwest.com
curl -4 ipwest.com
curl -6 ipwest.com
curl ipv4.ipwest.com
curl ipv6.ipwest.com
Linux shell 示例(变量赋值)
#!/bin/sh
ip="$(curl -fsS https://ipwest.com)"
echo "Current public IP: ${ip}"
Node.js
const res = await fetch('https://ipwest.com');
const ip = (await res.text()).trim();
console.log(ip);
Python
import requests
ip = requests.get('https://ipwest.com', timeout=5).text.strip()
print(ip)
PHP
<?php
$ip = trim(file_get_contents('https://ipwest.com'));
echo $ip;
四、注释说明 Notes
- 返回值是访问者当前公网出口 IP,不是内网地址。
- 若客户端启用 VPN Proxy,返回对应出口节点 IP。
- 双栈环境中,结果取决于客户端实际请求走的 IPv4 或 IPv6 通道。
- 不建议对结果做长期缓存,建议按业务实时获取。
五、应用场景 Use Cases
- DDNS 自动更新
- 服务器公网 IP 检测
- IPv6 连通性测试
- 自动防火墙白名单
- CI CD 出口确认
JSON IP
返回访客公网 IP 的 JSON 格式数据,支持 JSONP 回调。
Returns visitor public IP in JSON format with optional JSONP callback support.
一、功能说明 Overview
- 输出结构化 JSON,适合前端脚本直接消费。
- 成功响应仅包含一个字段:
ip。
- 支持
callback 参数返回 JSONP。
- 返回值为访问者当前公网出口 IP。
三、请求示例 Request Examples
curl "https://api.ipwest.com/jsonip"
curl "https://api.ipwest.com/jsonip?callback=getip"
五、注释说明 Notes
- 成功 JSON 响应固定为
{\"ip\":\"...\"},不附加其它元字段。
- 未传 callback 时返回
application/json。
- 传 callback 时返回
application/javascript。
- callback 仅允许合法函数名。
GeoIP (JSON)
查询目标 IP 或域名对应的 GeoIP 与网络信息,返回结构化 JSON 数据。
Query GeoIP and network attributes for an IP or domain, returned as structured JSON.
一、功能说明 Overview
- 用于获取 IP 地理位置与网络归属信息。
- 响应格式为 JSON(
application/json)。
- 输出结构固定为 5 个顶层字段:
ip、geo、network、flags、meta。
- 支持 IPv4 IPv6 Domain。
- 传入域名时,服务会先执行 DNS 解析,再返回解析到的 IP 信息。
二、接口地址 Endpoint
GET https://api.ipwest.com/geoip/{target}
{target} 支持 IPv4、IPv6 或域名 Domain。
- IPv4 示例:
8.8.8.8
- IPv6 示例:
2001:4860:4860::8888
- Domain 示例:
example.com
三、请求示例 Request Examples
curl "https://api.ipwest.com/geoip/8.8.8.8"
curl "https://api.ipwest.com/geoip/2001:4860:4860::8888"
curl "https://api.ipwest.com/geoip/example.com"
curl "https://api.ipwest.com/geoip/8.8.8.8?callback=getgeoip"
四、返回示例 Response Example JSON
{
"ip": "8.8.8.8",
"geo": {
"continent": "North America",
"country": "United States",
"country_code": "US",
"region": "CA",
"region_name": "California",
"city": "Mountain View",
"zip": "94043",
"latitude": 37.38605,
"longitude": -122.08385,
"timezone": "America/Los_Angeles"
},
"network": {
"reverse": "dns.google",
"isp": "Google LLC",
"org": "Google LLC",
"as_name": "GOOGLE",
"asn": 15169,
"as_org": "Google LLC"
},
"flags": {
"hosting": true,
"proxy": false,
"mobile": false
},
"meta": {
"source": "ip-api-pro",
"requested_at": "2026-02-16T08:10:00+08:00",
"cached": false,
"cache_group": "ip",
"cache_saved_at": "",
"ok": true
}
}
五、字段说明 Field Description
ip:目标 IP(由上游 query 映射而来)。
geo:地理信息分组,包含 continent/country/country_code/region/region_name/city/zip/latitude/longitude/timezone。
network:网络信息分组,包含 reverse/isp/org/as_name/asn/as_org。
flags:属性标记分组,包含 hosting/proxy/mobile。
meta:请求元信息分组,包含 source/requested_at/cached/cache_group/cache_saved_at/ok。
- 当
meta.ok=false 时,返回 meta.error.code 与 meta.error.message。
六、注释说明 Notes
Please note that the IP location database may not contain all information about a given IP. In this case, only the available data is displayed.
- 地理位置为 IP 归属地推断,不是精确定位。
- 域名查询会先进行 DNS 解析。
- 建议缓存 GeoIP 数据 7-30 天。
- 返回 Content-Type: application/json。
- 上游
status 字段不会透出,错误统一在 meta.error 返回。
Rate Limits
频率限制策略用于保证 API 服务稳定性与公平使用,避免滥用与瞬时流量冲击。
Rate limiting policy ensures API stability and fair usage while preventing abuse and burst overload.
一、概览 Overview
为保证服务稳定性与公平使用,IP 与 GeoIP REST API 实施频率限制。
To ensure service stability and fair usage, rate limits are enforced on IP and GeoIP REST APIs.
二、默认限制 Default Limits
- Plain Text IP:
60 requests / minute / IP
- GeoIP API:
30 requests / minute / IP
三、限制范围 Limit Scope
限流基于客户端公网 IP 计算。
Limits are enforced per client public IP.
四、超限响应 Exceeded Response
当请求超过限制时,服务返回 HTTP 429 Too Many Requests。
HTTP 429 Too Many Requests
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please slow down."
}
}
六、说明 Notes
- 建议缓存结果,尤其是 GeoIP 数据。
- 禁止滥用、扫描与高频非正常请求。
- 违规访问可能触发临时或长期封禁。
Error Codes
所有错误遵循标准 HTTP 状态码,并返回统一错误结构。
All errors follow standard HTTP status codes with a unified error payload.
一、概览 Overview
错误返回采用 HTTP 状态码 + JSON 错误对象。
Error responses use HTTP status codes plus JSON error object.
三、常见 HTTP 状态码 Common HTTP Status Codes
| HTTP |
Error Code |
说明 Description |
| 400 | INVALID_TARGET | 目标缺失或格式错误 / Target is missing or malformed |
| 400 | INVALID_IPV4 | IPv4 地址无效 / Invalid IPv4 address |
| 400 | INVALID_IPV6 | IPv6 地址无效 / Invalid IPv6 address |
| 400 | INVALID_DOMAIN | 域名格式无效 / Invalid domain format |
| 404 | NOT_FOUND | 接口或资源不存在 / Endpoint or resource not found |
| 429 | RATE_LIMIT_EXCEEDED | 超过请求频率限制 / Request rate limit exceeded |
| 500 | INTERNAL_ERROR | 服务器内部错误 / Internal server error |
| 503 | SERVICE_UNAVAILABLE | 服务暂时不可用 / Temporary service unavailable |
四、错误示例 Error Examples
400 示例
400 Example
{
"error": {
"code": "INVALID_TARGET",
"message": "Target must be a valid IPv4, IPv6, or domain."
}
}
429 示例
429 Example
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please slow down."
}
}
五、说明 Notes
- Plain Text 接口发生错误时可仅返回 HTTP 状态码与纯文本。
- GeoIP 接口错误返回 JSON 错误对象。
- 错误响应不暴露内部实现细节。