免费IP地址API
在您的脚本、应用和网站中使用MonIP。免费,无需注册,也无需API密钥。
接口端点
- GET https://monip.com/ip
- 以纯文本返回您的公网IP地址 – 非常适合脚本。
- GET https://monip.com/json
- 以JSON返回您的IP地址及国家、城市、坐标、运营商和ASN。
- GET https://monip.com/api/lookup?q=8.8.8.8
- 以JSON返回任意IPv4或IPv6地址或域名的详细信息。
- GET https://monip.com/api/lookup?q=example.com&lang=zh
- 添加 lang=… 可获取其他语言的国家和城市名称,例如 lang=de。
响应示例
$ curl "https://monip.com/api/lookup?q=8.8.8.8"
{
"ip": "8.8.8.8",
"version": 4,
"type": "public",
"hostname": "dns.google",
"country_code": "US",
"country": "美国",
"region": "California",
"city": "Mountain View",
"latitude": 37.422,
"longitude": -122.085,
"asn": "AS15169",
"isp": "Google LLC",
"network": null,
"tor": false
}
示例
# Bash
curl monip.com
curl -s monip.com/json | jq -r .country
# PowerShell
(Invoke-RestMethod https://monip.com/json).ip
# Python
import requests
print(requests.get("https://monip.com/api/lookup", params={"q": "8.8.8.8"}).json()["isp"])
// JavaScript
const me = await (await fetch("https://monip.com/json")).json();
console.log(me.ip, me.city, me.country);
限制与合理使用
每个IP地址每分钟最多 60 次查询。如需更多,请缓存结果 – IP位置很少变化。
已启用CORS,因此您可以在浏览器中直接通过JavaScript调用API。
位置数据:IP Geolocation by DB-IP(CC BY 4.0)。如果您在公开网站上使用该API,请添加指向 MonIP.com 的链接。