IP查询

大洲
国家
国家简码
邮编
纬度
经度
海拔
时区
运营商
地图

🧭 一、IP归属地查询工具介绍

IP归属地查询的作用是通过一个 IP 地址,获取其地理位置(国家、省、市)、运营商、是否为代理/VPN等信息。

🔧 主流IP归属地服务

服务平台免费/付费支持格式说明
ip-api.com免费,无需key(有限制)JSON信息详细,速率限制较宽松(每分钟 45 次)
ipinfo.io免费版 + 付费JSON支持城市、ASN、代理识别
ipip.net免费/企业版JSON/HTTP精度高,尤其适合中国地区
MaxMind GeoLite2免费/企业版本地库(.mmdb)用于高性能后端服务,本地查库无请求延迟

💻 二、常用语言调用示例


▶️ Python 示例(使用 ip-api)

import requests

def query_ip(ip="8.8.8.8"):
url = f"http://ip-api.com/json/{ip}"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print(f"IP: {ip}")
print(f"国家: {data['country']}, 地区: {data['regionName']}, 城市: {data['city']}")
print(f"运营商: {data['isp']}")
else:
print("查询失败")

query_ip("114.114.114.114")

▶️ JavaScript 示例(浏览器端调用)

<script>
fetch("http://ip-api.com/json/")
.then(res => res.json())
.then(data => {
console.log("你的IP:", data.query);
console.log("位置:", data.country, data.regionName, data.city);
console.log("ISP:", data.isp);
});
</script>

▶️ Node.js 示例(ipinfo.io)

const fetch = require('node-fetch');

async function queryIP(ip = "8.8.8.8") {
const res = await fetch(`https://ipinfo.io/${ip}/json`);
const data = await res.json();
console.log(`IP: ${data.ip}, 城市: ${data.city}, 国家: ${data.country}`);
}

queryIP();

▶️ Bash / Linux 命令行

curl http://ip-api.com/json/8.8.8.8

📦 三、本地库查询(MaxMind)

如果你不希望依赖外部服务,可以使用 MaxMind 的 GeoLite2 本地数据库:

Python + MaxMind 示例

import geoip2.database

reader = geoip2.database.Reader('GeoLite2-City.mmdb')
response = reader.city('8.8.8.8')

print(response.country.name)
print(response.subdivisions.most_specific.name)
print(response.city.name)

你需要:


🔐 四、安全性注意事项