OpenIPApi

API 文档

将 OpenIPApi 集成到您的应用程序所需的一切。基础 URL:https://api.openipapi.com(版本号为 /v1)。

信号,而非定论。 IP 情报是概率性的。threat_score 及 VPN/代理/Tor 标志是您决策逻辑的输入。请将它们与账户、支付、设备和行为信号结合——切勿仅以此作为封锁的唯一依据。详情请参阅数据方法论

认证

所有 API 请求必须在 X-API-Key 请求头中包含您的 API 密钥。您可以在 控制台.

X-API-Key: oip_your_api_key_here
请妥善保管您的 API 密钥,切勿在客户端 JavaScript 或公开仓库中暴露。

基础 URL

所有 API 请求均通过 HTTPS 发往以下基础 URL:

https://api.openipapi.com

机器可读规范 (OpenAPI 3.1): /openapi.yaml.

响应格式

所有响应均为 JSON。成功响应返回 HTTP 200. 错误响应返回相应的 4xx 或 5xx 状态码,并带有 error 字段。

{
  "error": "invalid_api_key",
  "message": "The provided API key is invalid or has been revoked.",
  "status": 401
}

GET /v1/lookup/{ip}

查询单个 IP 地址的地理位置、网络及威胁数据。

GET https://api.openipapi.com/v1/lookup/{ip}

参数

参数 类型 说明
ip path 要查询的 IPv4 或 IPv6 地址。
fields query (optional) 要返回的顶级字段,以逗号分隔: geo,network,threat,abuse.
date query (optional) 历史查询 — 返回该 IP 在指定日期的快照 (YYYY-MM-DD). 最多回溯 365 天,需要 Pro+. 若该日期无可用数据,返回 no_snapshot 错误。

响应字段

字段 说明 计划
ip The queried IP address. All
type IPv4 or IPv6. All
geo.country_code 2-letter ISO 3166-1 country code. All
geo.country Full country name. All
geo.region Region / state name. All
geo.region_code Region / state code. All
geo.city City name. All
geo.postal_code Postal / ZIP code. All
geo.latitude Latitude (decimal degrees). All
geo.longitude Longitude (decimal degrees). All
geo.timezone IANA timezone identifier (e.g. Europe/Berlin). All
geo.is_sanctioned True if the country is on OFAC, EU, or UN sanction lists. All
geo.sanction_lists Array of applicable sanction programs, e.g. ["OFAC","EU"]. All
network.asn Autonomous System Number. Starter+
network.as_name AS organisation name. Starter+
network.as_domain AS organisation domain. Starter+
network.isp Internet Service Provider name. All
network.organization Network organisation name. All
network.connection_type residential, datacenter, mobile, education, or government. All
threat.is_vpn True if the IP is a known VPN endpoint. Pro+
threat.is_proxy True if the IP is a known open proxy. Pro+
threat.is_tor True if the IP is a Tor exit node. Pro+
threat.is_relay True if the IP is an anonymous relay. Pro+
threat.is_hosting True if the IP belongs to a hosting provider. Pro+
threat.threat_score Composite risk score 0–100. A signal, not a final verdict — combine with account, payment, device and behavior data. Pro+
threat.threat_categories Array of threat category strings. Pro+
threat.bot_type Verified bot identifier (e.g. "googlebot", "bingbot") or null. Verified via reverse-DNS + forward confirmation. All
abuse.contact_email Abuse contact email from WHOIS data. Pro+

示例请求

$ curl https://api.openipapi.com/v1/lookup/185.220.101.45 \
     -H "X-API-Key: oip_your_api_key_here"

示例响应

{
  "ip": "185.220.101.45",
  "type": "IPv4",
  "geo": {
    "country_code": "DE",
    "country": "Germany",
    "region": "Hessen",
    "region_code": "HE",
    "city": "Frankfurt am Main",
    "postal_code": "60313",
    "latitude": 50.1109,
    "longitude": 8.6821,
    "timezone": "Europe/Berlin",
    "is_sanctioned": false,
    "sanction_lists": []
  },
  "network": {
    "asn": 205100,
    "as_name": "F3 Netze e.V.",
    "as_domain": "f3netze.de",
    "isp": "F3 Netze",
    "organization": "F3 Netze e.V.",
    "connection_type": "datacenter"
  },
  "threat": {
    "is_vpn": true,
    "is_proxy": false,
    "is_tor": true,
    "is_relay": false,
    "is_hosting": true,
    "threat_score": 85,
    "threat_categories": ["tor_exit_node", "known_abuser"],
    "bot_type": null
  },
  "abuse": {
    "contact_email": "abuse@f3netze.de"
  }
}

POST /v1/lookup/batch

单次请求查询多个 IP 地址。批量大小限制取决于您的计划。

POST https://api.openipapi.com/v1/lookup/batch
批量查询需要 Starter 计划或更高版本,免费计划账户将收到 plan_required 错误。

批量大小限制

计划 每次请求最多 IP 数
Starter 100
Pro 500
Business 1,000
Enterprise 5,000

请求体

{
  "ips": [
    "185.220.101.45",
    "8.8.8.8",
    "1.1.1.1"
  ]
}

响应

返回完整查询对象的封装数组,顺序与请求一致。

{
  "results": [
    { "ip": "185.220.101.45", /* full lookup object */ },
    { "ip": "8.8.8.8",          /* full lookup object */ },
    { "ip": "1.1.1.1",          /* full lookup object */ }
  ],
  "count": 3
}

GET /v1/me

返回发起请求的 IP 地址的地理位置和威胁数据,适用于"我的 IP 是什么"功能。

GET https://api.openipapi.com/v1/me

响应与 GET /v1/lookup/{ip} 相同,但已预填调用方 IP。

$ curl https://api.openipapi.com/v1/me \
     -H "X-API-Key: oip_your_api_key_here"

GET /v1/asn/{asn}

获取自治系统编号的详细信息。需要 Starter 计划或更高版本。

GET https://api.openipapi.com/v1/asn/{asn}

asn 参数同时接受 13335AS13335 格式。

$ curl https://api.openipapi.com/v1/asn/13335 \
     -H "X-API-Key: oip_your_api_key_here"

示例响应

{
  "asn": 13335,
  "as_name": "Cloudflare, Inc.",
  "as_domain": "cloudflare.com",
  "organization": "Cloudflare, Inc.",
  "country_code": "US",
  "ip_ranges_count": 1284,
  "total_ips": 2359296
}

GET /v1/validate/{ip}

验证 IP 地址并判断其类型,不消耗查询配额。

GET https://api.openipapi.com/v1/validate/{ip}

Example response

{
  "ip": "185.220.101.45",
  "valid": true,
  "type": "IPv4",
  "private": false,
  "bogon": false
}

GET /v1/fraud/{ip}

综合欺诈评分(0–100),含风险级别和可操作建议。综合 VPN、代理、Tor、数据中心及历史滥用信号。 Starter 计划及以上

GET https://api.openipapi.com/v1/fraud/{ip}

Example response

{
  "ip": "185.220.101.45",
  "fraud_score": 92,
  "risk_level": "critical",
  "signals": {
    "is_vpn": true,
    "is_proxy": false,
    "is_tor": true,
    "is_datacenter": true,
    "is_known_attacker": true,
    "high_risk_country": false
  },
  "recommendation": "block"
}

风险级别与建议

评分 风险级别 建议 典型操作
0–30lowallow放行请求
31–60mediumreview记录以供人工审核
61–85highchallenge要求 CAPTCHA / 2FA / 升级认证
86–100criticalblock拒绝并告警

GET /v1/probe/{ip}

来自我们 60+ 个主动探测节点的实时网络探测数据:开放 TCP 端口、服务横幅、反向 DNS、完整 TLS 证书详情(主题、颁发者、SAN、有效期)及检测到的服务类别。 Pro 计划及以上

GET https://api.openipapi.com/v1/probe/{ip}

工作原理

  • · 新鲜数据(≤ 7 天): 立即从缓存返回。
  • · 陈旧数据(> 7 天): 立即返回同时在后台排队重新探测。响应包含 "stale": true.
  • · 从未探测过: 立即排队进行扫描,首次结果通常在 1–5 分钟内返回。
  • · 探测配额为每月查询配额的 10%。私有/保留 IP 无法被探测。

Example response

{
  "ip": "185.220.101.45",
  "reachable": true,
  "last_probed": "2026-04-18T14:23:11+00:00",
  "age_hours": 2.3,
  "stale": false,
  "refresh_queued": false,
  "probe_count_24h": 14,
  "probed_from_nodes": 8,
  "open_ports": [
    { "port": 22,   "service": "ssh",       "banner": "SSH-2.0-OpenSSH_8.9p1" },
    { "port": 80,   "service": "http",      "banner": "nginx/1.24.0" },
    { "port": 443,  "service": "https",     "banner": null },
    { "port": 9001, "service": "tor-relay", "banner": null }
  ],
  "reverse_dns": "tor-exit.f3netze.de",
  "tls": {
    "subject_cn":  "*.f3netze.de",
    "issuer":      "Let's Encrypt",
    "valid_from":  "2026-02-10T00:00:00Z",
    "valid_to":    "2026-05-10T00:00:00Z",
    "sans":        ["f3netze.de", "*.f3netze.de"],
    "fingerprint": "7e:4f:...:b2:e1"
  },
  "banners": {
    "22": "SSH-2.0-OpenSSH_8.9p1",
    "80": "nginx/1.24.0"
  },
  "detected_services": {
    "is_tor_relay":  true,
    "is_ssh_open":   true,
    "is_web_server": true,
    "is_vpn":        false,
    "is_proxy":      false
  }
}

我们扫描的端口

22 (ssh), 80 / 8080 (http), 443 / 8443 (https), 1080 (socks5), 3128 / 8888 (http-proxy), 9001 / 9030 (tor-relay / tor-dir), 9050 / 9150 (tor-socks), 1194 (openvpn), 4500 (ipsec-nat-t), 51820 (wireguard).

使用场景

  • · 反欺诈——检测运行相同 SSH 版本/TLS 指纹的机器人农场
  • · 威胁情报——监控 C2 服务器的横幅/证书变化
  • · OSINT / 漏洞赏金——快速枚举任意公网 IP 上的服务
  • · 托管 / ISP 运维——在您的网络中发现开放代理 / Tor 出口

GET /v1/proxy-attribution/{ip}

识别 IP 是否属于已知住宅代理池、商业 VPN 或数据中心范围。与通用 is_proxy 标志不同,此端点将 IP 归因至具体提供商(Bright Data、Oxylabs、NordVPN 等)——对于需要放行某些提供商而封锁其他提供商的欺诈团队而言至关重要。 代理情报附加功能

GET https://api.openipapi.com/v1/proxy-attribution/{ip}

示例响应(IP 在 VPN 范围内)

{
  "ip": "2.56.16.42",
  "detected": true,
  "primary_provider": {
    "provider":     "unknown_vpn",
    "display_name": "Unknown VPN",
    "network_type": "vpn",
    "confidence":   0.75
  },
  "networks": [
    {
      "provider":    "unknown_vpn",
      "network_type": "vpn",
      "confidence":   0.75,
      "source":       "x4bnet-vpn",
      "cidr":         "2.56.16.0/22"
    },
    {
      "provider":    "unknown_datacenter",
      "network_type": "datacenter",
      "confidence":   0.75,
      "source":       "x4bnet-datacenter"
    }
  ],
  "recommendation": "treat_as_vpn"
}

网络类型

  • · residential — 住宅代理池(Bright Data、Oxylabs、Smartproxy、IPRoyal、Hola、Honeygain、EarnApp、Peer2Profit、SOAX)
  • · vpn — 商业 VPN 提供商(NordVPN、ExpressVPN、Surfshark、Mullvad、ProtonVPN、PIA、IPVanish、CyberGhost)
  • · datacenter — 常用于商业代理出口的托管提供商(AWS、DigitalOcean、OVH、Hetzner 等)
  • · tor — Tor 出口/中继节点
  • · mobile — 移动运营商代理池

建议

建议 含义
no_proxy_detectedIP 未匹配任何已知池——视为正常流量。
treat_as_commercial_proxyIP 在住宅代理池中——在非爬虫网站上可能存在恶意行为。
treat_as_vpnIP 在商业 VPN 范围内——应用 VPN 策略。
treat_as_datacenterIP 来自数据中心——并非真实住宅用户。
block_or_challengeTor 出口——封锁或要求强认证。

GET /v1/account/usage

返回您账户当前计费周期的用量统计数据。

GET https://api.openipapi.com/v1/account/usage

Example response

{
  "plan": "Pro",
  "period_start": "2026-03-01",
  "period_end": "2026-03-31",
  "lookups_used": 184320,
  "lookups_limit": 500000,
  "lookups_remaining": 315680,
  "reset_at": "2026-04-01T00:00:00Z"
}

GET /v1/database/list

列出您当前计划可用的 MMDB 数据库。即插即用的 MaxMind .mmdb 替代方案,适用于离线/边缘使用——兼容任何 MaxMind DB 读取器(PHP、Go、Python、Node.js、Rust、Java)。

GET https://api.openipapi.com/v1/database/list

Example response

{
  "plan": "Business",
  "sources": [
    {
      "source": "country",
      "filename": "geo-whois-asn-country.mmdb",
      "size_bytes": 8225621,
      "updated_at": "2026-04-18T02:00:00+00:00",
      "etag": "\"fa2b851f9155838b\"",
      "download_url": "https://api.openipapi.com/v1/database/download/country"
    }
  ]
}

GET /v1/database/download/{source}

流式传输原始 MMDB 文件,支持 ETag + If-None-Match 条件 GET(文件未变更时返回 304 Not Modified)。速率限制:每个来源每天 10 次下载。

GET https://api.openipapi.com/v1/database/download/{source}

可用来源

来源 内容 许可证 所需计划
country国家代码 + ASNCC0Pro
asnASN + 组织CC0Business
city-geolite2城市、地区、经纬度、时区(GeoLite2)MaxMind GeoLite2 EULABusiness
city-dbip城市(GeoLite2 的替代方案)DB-IP LiteEnterprise

示例:下载并在 PHP 中使用

# Download latest MMDB
$ curl -H "X-API-Key: YOUR_KEY" \
    -o asn.mmdb \
    https://api.openipapi.com/v1/database/download/asn

# Use with maxmind-db/reader
$ composer require maxmind-db/reader

<?php
use MaxMind\Db\Reader;
$reader = new Reader('asn.mmdb');
$record = $reader->get('8.8.8.8');
// ['autonomous_system_number' => 15169,
//  'autonomous_system_organization' => 'Google LLC']

制裁标志

每个 /v1/lookup 响应在 geo 块中包含两个字段,告知您该 IP 所在国家是否受到国际制裁。

字段 说明
geo.is_sanctioned true 若该国家出现在任何受监控的制裁列表中; false 否则。
geo.sanction_lists 适用的制裁计划标识符数组: OFAC, EU, UN, UK. 空数组 [] 表示未受制裁。

涵盖制裁列表:OFAC(美国)、欧盟、联合国安理会、英国 OFSI。目前标记的国家包括伊朗、朝鲜、俄罗斯、白俄罗斯、叙利亚、古巴、委内瑞拉、苏丹等。该列表随计划变化持续维护更新。

受制裁国家示例

"geo": {
  "country_code": "IR",
  "country": "Iran",
  ...
  "is_sanctioned": true,
  "sanction_lists": ["OFAC", "EU", "UN"]
}

机器人检测

OpenIPApi 执行 双向反向 DNS 验证 以识别合法爬虫。结果可在每次查询的 threat.bot_type 中获取。

字段 取值
threat.bot_type null (非已验证机器人)或以下之一: googlebot, google_special_crawl, bingbot, applebot, yandexbot, duckduckbot, facebookbot, semrushbot, ahrefsbot, mj12bot

验证方法:(1) 对 IP 进行 PTR 查询 → 主机名。(2) 主机名必须匹配机器人的域名模式(例如 *.googlebot.com). (3) 对主机名进行正向 DNS 解析必须返回原始 IP。结果缓存 24 小时。

已验证 Googlebot 示例

"threat": {
  "is_vpn": false,
  "is_proxy": false,
  "is_tor": false,
  "threat_score": 0,
  "bot_type": "googlebot"
}

历史查询

在任意单个 IP 查询中添加 ?date=YYYY-MM-DD 参数,可获取该日期的数据快照。

历史查询需要 Pro 计划或更高版本。快照可回溯最多 365 天。系统每天自动为查询最频繁的 IP 生成快照。
GET https://api.openipapi.com/v1/lookup/{ip}?date=2026-01-15

示例请求

$ curl "https://api.openipapi.com/v1/lookup/185.220.101.45?date=2026-01-15" \
     -H "X-API-Key: oip_your_api_key_here"

响应封装

{
  "ip": "185.220.101.45",
  "snapshot_date": "2026-01-15",
  "is_historical": true,
  "data": {
    /* standard lookup response */
  }
}

错误:无可用快照

{
  "error": "No historical snapshot available for this IP on 2026-01-15",
  "code": "no_snapshot"
}

错误码

代码 HTTP 状态 说明
invalid_api_key 401 API 密钥缺失、格式错误或已被撤销。
limit_exceeded 429 您已用完当前计费周期的所有查询次数。
plan_required 403 您当前的计划不支持所请求的功能。
invalid_ip 400 提供的 IP 地址不是有效的 IPv4 或 IPv6 地址。
not_found 404 未找到所请求资源的数据(例如,未知 ASN)。
no_snapshot 404 该 IP 在所请求日期不存在历史快照。
date_out_of_range 400 历史查询日期超过 365 天前。
invalid_date 400 日期参数缺失、格式错误或为未来日期。
plan_upgrade_required 403 所请求的功能需要更高级别的计划。
rate_limited 429 短时间内请求过多,请退避后重试。
internal_error 500 发生意外服务器错误。如持续出现,请联系支持。

速率限制

除每月查询配额外,每个 API 密钥通过滑动窗口限制请求速率。超出后 API 返回 HTTP 429 并带有 Retry-After 请求头。

计划 请求次数/分钟 查询次数/月
Free 30 10,000
Starter 120 100,000
Pro 300 500,000
Business 600 2,000,000
Enterprise Custom Unlimited

其他限制: /v1/validate (未认证)每个调用方 IP 限 60 次/分钟; /v1/me 限 30 次/分钟。MMDB 下载每个来源每个账户每天限 10 次。速率限制响应包含 Retry-After.

Webhooks

Webhooks 允许您在所监控 IP 的状态发生变化时接收实时 HTTP POST 通知。 在 控制台 → Webhooks, 或仪表板 UI 中进行配置,无需 API 调用。

事件

事件 触发条件
vpn_detected被监控的 IP 新检测为 VPN 端点。
tor_detected被监控的 IP 出现在 Tor 出口节点列表中或被探测为 Tor 中继。
proxy_detected被监控的 IP 被检测为开放代理或 SOCKS 代理。
high_threat威胁评分超过您配置的阈值(50–95)。

请求头

POST https://your-endpoint.example.com/webhook
Content-Type: application/json
User-Agent: OpenIPApi-Webhook/1.0
X-OpenIPApi-Event: high_threat
X-OpenIPApi-Signature: sha256=8c7f1a...b2e

示例载荷

{
  "event": "high_threat",
  "delivered_at": "2026-04-18T12:34:56Z",
  "webhook_id": 142,
  "data": {
    "ip": "185.220.101.45",
    "threat_score": 92,
    "previous_score": 45,
    "is_tor": true,
    "is_vpn": true
  }
}

验证签名

每个 Webhook 均使用原始 JSON 请求体与您的 Webhook 密钥进行 HMAC-SHA256 签名。签名通过 X-OpenIPApi-Signature 请求头以 sha256=<hex>. 形式发送。在处理载荷前请务必验证:

PHP

$body = file_get_contents('php://input');
$hdr  = $_SERVER['HTTP_X_OPENIPAPI_SIGNATURE'] ?? '';
$expected = 'sha256=' . hash_hmac(
    'sha256', $body, $webhookSecret
);
if (!hash_equals($expected, $hdr)) {
    http_response_code(401);
    exit;
}
// Safe to process $body now

Node.js (Express)

const crypto = require('crypto');

app.post('/webhook',
  express.raw({ type: 'application/json' }),
  (req, res) => {
    const hdr = req.headers['x-openipapi-signature'];
    const expected = 'sha256=' + crypto
      .createHmac('sha256', process.env.WEBHOOK_SECRET)
      .update(req.body).digest('hex');
    if (expected !== hdr) return res.status(401).end();
    // Process JSON.parse(req.body)
  });

重试策略

您的端点必须在 10 秒内以 HTTP 2xx 响应以确认接收。任何其他状态(或超时)将触发指数退避重试:1 分钟、5 分钟、30 分钟、2 小时、12 小时。最终尝试失败后,Webhook 将标记为失败并在仪表板中发出告警。

投递历史与重放

控制台 → Webhooks 记录每个账户最近 100 次投递尝试,显示事件类型、HTTP 状态码及您端点返回的响应体。您可以 重放 任何历史投递以重新发送原始签名载荷,并使用内置 签名调试器 在客户端验证 HMAC-SHA256 签名,无需向任何服务器共享您的密钥。

重放的投递包含额外的 X-OpenIPApi-Replay: 1 请求头,以便您的端点区分重放与实时事件。

代码示例 — curl

单个查询

$ curl https://api.openipapi.com/v1/lookup/8.8.8.8 \
     -H "X-API-Key: oip_your_api_key_here"

批量查询

$ curl -X POST https://api.openipapi.com/v1/lookup/batch \
     -H "X-API-Key: oip_your_api_key_here" \
     -H "Content-Type: application/json" \
     -d '{"ips": ["8.8.8.8", "1.1.1.1", "185.220.101.45"]}'

我的 IP

$ curl https://api.openipapi.com/v1/me \
     -H "X-API-Key: oip_your_api_key_here"

代码示例 — JavaScript

单个查询(fetch)

const response = await fetch('https://api.openipapi.com/v1/lookup/8.8.8.8', {
  headers: {
    'X-API-Key': 'oip_your_api_key_here'
  }
});

const data = await response.json();
console.log(data.geo.country);       // "United States"
console.log(data.threat.is_vpn);     // false
console.log(data.threat.threat_score); // 0

批量查询

const response = await fetch('https://api.openipapi.com/v1/lookup/batch', {
  method: 'POST',
  headers: {
    'X-API-Key': 'oip_your_api_key_here',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    ips: ['8.8.8.8', '1.1.1.1', '185.220.101.45']
  })
});

const { results } = await response.json();
for (const info of results) {
  console.log(info.ip, info.geo.city, info.threat.threat_score);
}

代码示例 — Python

单个查询(requests)

import requests

API_KEY = "oip_your_api_key_here"
headers = {"X-API-Key": API_KEY}

r = requests.get(
    "https://api.openipapi.com/v1/lookup/8.8.8.8",
    headers=headers
)
r.raise_for_status()
data = r.json()

print(data["geo"]["country"])       # United States
print(data["threat"]["is_vpn"])     # False
print(data["threat"]["threat_score"]) # 0

批量查询

import requests

API_KEY = "oip_your_api_key_here"
headers = {
    "X-API-Key": API_KEY,
    "Content-Type": "application/json"
}

payload = {
    "ips": ["8.8.8.8", "1.1.1.1", "185.220.101.45"]
}

r = requests.post(
    "https://api.openipapi.com/v1/lookup/batch",
    json=payload,
    headers=headers
)
r.raise_for_status()

for info in r.json()["results"]:
    print(info["ip"], info["geo"]["city"], info["threat"]["threat_score"])

准备好开始了吗?

每月 10,000 次免费查询,无需信用卡。

获取免费 API 密钥