IPinfo技能使用说明
2026-04-01
新闻来源:网淘吧
围观:29
电脑广告
手机广告
IPinfo地理位置服务
免费的IP地理位置API。基础使用(每月5万次请求)无需API密钥,如需更高限制可选择使用令牌。
配置
环境变量IPINFO_TOKEN是可选的——不使用它也能通过免费套餐正常工作。如需更高请求频率限制,可通过OpenClaw仪表板界面配置,或手动设置:

- 仪表板界面:在OpenClaw仪表板中配置
IPINFO_TOKEN(可选) - 环境变量:
export IPINFO_TOKEN="你的令牌" - 查询参数:
?token=你的令牌(适用于一次性请求)
快速查询
单个IP:
curl -s "https://ipinfo.io/8.8.8.8"
当前IP:
curl -s "https://ipinfo.io/json"
使用令牌(可选,来自环境):
curl -s "https://ipinfo.io/8.8.8.8?token=${IPINFO_TOKEN}"
或直接传递令牌:
curl -s "https://ipinfo.io/8.8.8.8?token=YOUR_TOKEN"
响应格式
JSON响应包含:
ip:IP地址hostname:反向DNS主机名city:城市名称region:州/地区country:两位字母国家代码(ISO 3166-1 alpha-2)postal:邮政编码timezone:IANA时区loc:坐标,格式为“纬度,经度”org:组织/ASN信息
提取特定字段
使用jq仅限国家:
curl -s "https://ipinfo.io/8.8.8.8" | jq -r '.city, .country, .loc'
解析坐标:
curl -s "https://ipinfo.io/8.8.8.8" | jq -r '.country'
批量处理
curl -s "https://ipinfo.io/8.8.8.8" | jq -r '.loc' | tr ',' '\n'
处理多个IP:
Python用法
for ip in 8.8.8.8 1.1.1.1 208.67.222.222; do
if [ -n "$IPINFO_TOKEN" ]; then
echo "$ip: $(curl -s "https://ipinfo.io/$ip?token=$IPINFO_TOKEN" | jq -r '.city, .country' | tr '\n' ', ')"
else
echo "$ip: $(curl -s "https://ipinfo.io/$ip" | jq -r '.city, .country' | tr '\n' ', ')"
fi
done
使用环境变量中的令牌:
import os
import requests
# Without token (free tier)
response = requests.get("https://ipinfo.io/8.8.8.8")
data = response.json()
print(f"{data['city']}, {data['country']}")
print(f"Coordinates: {data['loc']}")
或直接传递令牌:
import os
import requests
token = os.getenv("IPINFO_TOKEN")
if token:
response = requests.get("https://ipinfo.io/8.8.8.8", params={"token": token})
else:
response = requests.get("https://ipinfo.io/8.8.8.8")
data = response.json()
速率限制
response = requests.get("https://ipinfo.io/8.8.8.8", params={"token": "YOUR_TOKEN"})
免费层:每月50,000次请求,约每秒1次请求
- 使用令牌:根据套餐有更高的限制
- 配置
- IPINFO_TOKEN
通过OpenClaw仪表盘UI或环境变量常见用例
IP地址地理位置定位
- 用位置数据丰富IP列表
- 按国家筛选IP
- 使用坐标计算IP之间的距离
- IP的时区检测
- Timezone detection for IPs
文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~