IP地理位置信息查询
接口说明
该接口是一个IP地理位置信息查询服务,能够对IP地理位置信息进行查询。支持输入IP值,根据不同的查询实体返回信息,返回信息包括国家、省份、城市、经度坐标、纬度坐标、注册机构、网络类型等地理位置相关信息。
请求地址
https://api.f.360.cn/custom/iplib/internal/v3/ip_geo/:ip
请求方法
POST
请求参数
| 参数名 | 类型 | 位置 | 是否必填 | 示例值 |
|---|---|---|---|---|
| ip | string | path | 是 | 34.107.19.249 |
响应参数
| 名称 | 类型 | 示例值 | 描述 |
|---|---|---|---|
| errno | Int | 200 | 状态码 |
| msg | string | success | 结果说明 |
| result | object | 查询结果 | |
| result.network_location | object | 位置 | |
| result.network_location.accuracy | integer | 6 | 精度 |
| result.network_location.as | string | CHINANET-Qinghai-AS-AP | AS组织名称 |
| result.network_location.asn | integer | 140061 | ASN |
| result.network_location.city | string | 海西蒙古族藏族自治州 | 城市 |
| result.network_location.country | string | 中国 | 国家 |
| result.network_location.district | string | 朝阳区 | 区县 |
| result.network_location.latitude | string | 37.86306600 | 纬度坐标 |
| result.network_location.longitude | string | 8.68747300 | 经度坐标 |
| result.network_location.operator | string | 中国电信 | 中国电信 |
| result.network_location.time_zone | string | 时区 | |
| result.network_location.province | string | 青海省 | 省份/州 |
| result.summary | object | 摘要 | |
| result.summary.anonymous_type | string | VPN | 匿类型踪 |
| result.summary.user_type | string | 该IP的用户类型 | |
| result.summary.geo_info | object | 地理信息 | |
| result.summary.geo_info.as | string | CHINANET-Qinghai-AS-AP | AS组织名称 |
| result.summary.geo_info.asn | integer | 140061 | ASN |
| result.summary.geo_info.city | string | 海西蒙古族藏族自治州 | 城市 |
| result.summary.geo_info.continent | string | 亚洲 | 洲 |
| result.summary.geo_info.country | string | 中国 | 国家 |
| result.summary.geo_info.district | string | 朝阳区 | 区县 |
| result.summary.geo_info.operator | string | 中国电信 | IP注册机构 |
| result.summary.geo_info.areacode | string | CN | 国家编码 |
| result.summary.geo_info.province | string | 青海省 | 省份/州 |
| result.summary.network_type | Array(string) | 已使用 | IP的网络类型 |
| result.user_info | object | 用户信息 | |
| result.user_info.user_type | string | 该IP的用户类型 | |
| result.user_info.user | string | 该IP的用户 |
请求示例
支持cUrl、Python、Java、PHP、Go语言的请求,示例如下
#!/usr/bin/env bash
set -euo pipefail
APPID="" # apikey
SECRET="" # salt
URL="https://api.f.360.cn/custom/iplib/internal/v3/ip_geo/34.107.19.249"
BODY='{}'
NONCE=$(printf '%08d' $((RANDOM % 100000000)))
TIMESTAMP=$(date +%s)
BODY_MD5=$(printf '%s' "$BODY" | openssl dgst -md5 -hex | awk '{print $NF}')
SIGNATURE=$(printf '%s' "${BODY_MD5}${APPID}${NONCE}${TIMESTAMP}${SECRET}" | openssl dgst -md5 -hex | awk '{print $NF}')
SIGNATURE=${SIGNATURE:16}
curl --location --request POST "$URL" \
--header "Content-Type: application/json" \
--header "X-360-Key: ${APPID}" \
--header "X-360-Nonce: ${NONCE}" \
--header "X-360-Timestamp: ${TIMESTAMP}" \
--header "X-360-Signature: ${SIGNATURE}" \
--data "${BODY}"# -*- coding:utf-8 -*-
import hashlib
import json
import random
import time
import requests
APPID = "" # apikey
SECRET = "" # salt
def make_headers(appid, secret, body):
headers = {}
headers["X-360-Key"] = appid
headers["X-360-Nonce"] = str(random.randint(0, 99999999)).zfill(8)
headers["X-360-Timestamp"] = str(int(time.time()))
s = (
hashlib.md5(body.encode("utf8")).hexdigest()
+ headers["X-360-Key"]
+ headers["X-360-Nonce"]
+ headers["X-360-Timestamp"]
+ secret
)
md5 = hashlib.md5(s.encode("utf8")).hexdigest()
headers["X-360-Signature"] = md5[16:]
headers["Content-Type"] = "application/json"
return headers
def do_post(url, body):
res = requests.post(
url,
data=json.dumps(params),
headers=make_headers(APPID, SECRET, json.dumps(body)),
)
print(res.text)
if __name__ == "__main__":
# 请求地址
url = "https://api.f.360.cn/custom/iplib/internal/v3/ip_geo/34.107.19.249"
# 查询参数
params = {}
do_post(url, params)import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.concurrent.ThreadLocalRandom;
public class Demo {
static String md5(String input) throws Exception {
byte[] digest = MessageDigest.getInstance("MD5")
.digest(input.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append(String.format("%02x", b & 0xff));
}
return sb.toString();
}
public static void main(String[] args) throws Exception {
String appid = ""; // apikey
String secret = ""; // salt
String url = "https://api.f.360.cn/custom/iplib/internal/v3/ip_geo/34.107.19.249";
String body = "{}";
String nonce = String.format("%08d", ThreadLocalRandom.current().nextInt(100000000));
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
String signature = md5(md5(body) + appid + nonce + timestamp + secret).substring(16);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("X-360-Key", appid)
.header("X-360-Nonce", nonce)
.header("X-360-Timestamp", timestamp)
.header("X-360-Signature", signature)
.POST(HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
System.out.println(response.body());
}
}<?php
// apikey
$appid = "";
// salt
$secret = "";
$url = 'https://api.f.360.cn/custom/iplib/internal/v3/ip_geo/34.107.19.249';
$body = json_encode([], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$nonce = str_pad((string) random_int(0, 99999999), 8, "0", STR_PAD_LEFT);
$timestamp = (string) time();
$signature = substr(md5(md5($body) . $appid . $nonce . $timestamp . $secret), 16);
$ch = curl_init($url);
$options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-360-Key: {$appid}",
"X-360-Nonce: {$nonce}",
"X-360-Timestamp: {$timestamp}",
"X-360-Signature: {$signature}",
],
];
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $body;
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
if ($response === false) {
echo curl_error($ch), PHP_EOL;
} else {
echo $response, PHP_EOL;
}
curl_close($ch);package main
import (
"bytes"
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"math/rand"
"net/http"
"time"
)
func md5Hex(s string) string {
sum := md5.Sum([]byte(s))
return hex.EncodeToString(sum[:])
}
func main() {
appid := "" // apikey
secret := "" // salt
url := "https://api.f.360.cn/custom/iplib/internal/v3/ip_geo/34.107.19.249"
body := []byte(`{}`)
nonce := fmt.Sprintf("%08d", rand.Intn(100000000))
timestamp := fmt.Sprintf("%d", time.Now().Unix())
signature := md5Hex(md5Hex(string(body)) + appid + nonce + timestamp + secret)[16:]
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-360-Key", appid)
req.Header.Set("X-360-Nonce", nonce)
req.Header.Set("X-360-Timestamp", timestamp)
req.Header.Set("X-360-Signature", signature)
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(respBody))
}响应示例
业务正常响应
{
"errno": 2000,
"from": "360威胁情报中心",
"invalid": [],
"msg": "success",
"result": {
"summary": {
"geo_info": {
"continent": "欧洲",
"country": "德国",
"areacode": "DE",
"province": "黑森州",
"city": "美因河畔法兰克福",
"district": "",
"asn": 396982,
"as": "GOOGLE-CLOUD-PLATFORM",
"operator": "谷歌公司"
},
"network_type": ["已使用"],
"user_type": "",
"anonymous_type": ""
},
"network_location": {
"country": "德国",
"province": "黑森州",
"city": "美因河畔法兰克福",
"district": "",
"accuracy": 4,
"time_zone": "UTC+1",
"longitude": "8.68747300",
"latitude": "50.11080900",
"asn": 396982,
"as": "GOOGLE-CLOUD-PLATFORM",
"operator": "谷歌公司"
},
"user_info": {
"user_type": "",
"user": ""
}
}
}业务异常响应
{
"errno": 2000,
"from": "360威胁情报中心",
"invalid": [
"266.266.1.1"
],
"msg": "success",
"result": {}
}