输入 IP 地址,返回归属地信息与文化典故。国内返回诗词,国外返回景点故事。
查询指定 IP 的归属地信息与文化典故。不传 ip 参数则返回当前客户端 IP 的信息。
curl "./?ip=114.114.114.114"
{
"code": 200,
"success": true,
"ip": "114.114.114.114",
"location": {
"country": "中国",
"region": "江苏",
"city": "南京",
"district": null,
"isp": "China Telecom"
},
"culture": {
"type": "poem",
"content": "姑苏城外寒山寺,夜半钟声到客船。"
}
}
{
"code": 200,
"success": true,
"ip": "8.8.8.8",
"location": {
"country": "美国",
"region": "加利福尼亚州",
"city": "山景城",
"district": null,
"isp": "Google LLC"
},
"culture": {
"type": "story",
"content": "自由女神像:矗立在纽约港的巨型铜像,象征自由与民主,是法国于1886年赠送给美国的礼物。"
}
}
{
"code": 503,
"success": false,
"ip": "8.8.8.8",
"error": "归属地查询失败(API超时或网络错误)",
"location": null,
"culture": null
}
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
ip |
string | 选填 | 客户端 IP | 要查询的 IP 地址,不传则返回当前客户端 IP 信息 |
async function queryIp(ip) {
const url = `./?ip=${ip}`;
const response = await fetch(url);
const data = await response.json();
if (data.success) {
console.log(`归属地:${data.location.country} ${data.location.region}`);
console.log(`文化:${data.culture.content}`);
}
}
queryIp('114.114.114.114');
import requests
def query_ip(ip):
url = f'./?ip={ip}'
response = requests.get(url, timeout=10)
data = response.json()
if data['success']:
loc = data['location']
print(f"归属地:{loc['country']} {loc['region']} {loc['city']}")
print(f"文化:{data['culture']['content']}")
else:
print(f"查询失败:{data['error']}")
query_ip('114.114.114.114')
<?php
function queryIp($ip) {
$url = "./?ip=" . urlencode($ip);
$response = file_get_contents($url);
$data = json_decode($response, true);
if ($data['success']) {
$loc = $data['location'];
echo "归属地:{$loc['country']} {$loc['region']}\n";
echo "文化:{$data['culture']['content']}\n";
}
}
queryIp('114.114.114.114');
const https = require('https');
function queryIp(ip) {
const url = `./?ip=${encodeURIComponent(ip)}`;
https.get(url, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
const result = JSON.parse(data);
if (result.success) {
console.log(`归属地:${result.location.country} ${result.location.region}`);
console.log(`文化:${result.culture.content}`);
}
});
});
}
queryIp('114.114.114.114');
location.country 国家 · location.region 省份/州 · location.city 城市location.isp 运营商 · culture.type poem/story · culture.content 文化内容