GeoIPy API

GeoIPy provides a robust, real-time IP to geolocation API that can accurately determine location data and identify potential security threats from high-risk IP addresses. The results are delivered in a matter of milliseconds in JSON format. With GeoIPy's API, you can instantly pinpoint website visitors' locations and tailor your user experience and application accordingly.

This documentation comprehensively covers the API features, available options, and integration guides for various programming languages.

API访问令牌

您的API访问令牌用作访问GeoIPy API的唯一身份验证凭据。要使用API进行身份验证,请在API的基本URL中包含access_key参数,并将其赋值为您的访问令牌的值。

令牌URL:
https://www.geoipy.com/

附加您的API访问密钥:下面的示例演示了如何在API请求中使用GeoIPy API进行身份验证:
https://www.geoipy.com/api/IPsInfo/?ip=@(Model.IP)
&key=@(Key)

API输出

GeoIPy API可以以JSON格式或其他格式提供数据。以下示例演示了GeoIPy针对先前部分中的API调用返回的API结果,该调用请求了IP地址为@(Model.IP)的信息。

{
  "ip": "18.191.200.108",
  "hostname": "ec2-18-191-200-108.us-east-2.compute.amazonaws.com",
  "type": "ipv4",
  "continent_code": "NA",
  "continent_name": "North America",
  "country_code": "US",
  "country_name": "United States",
  "region_code": "OH",
  "region_name": "Ohio",
  "city": "Columbus",
  "zip": "43201",
  "latitude": 39.995578765869141,
  "longitude": -82.999458312988281,
  "msa": "18140",
  "dma": "535",
  "radius": "41.01305",
  "ip_routing_type": "fixed",
  "connection_type": "tx",
  "location": {
    "geoname_id": 4509177,
    "capital": "Washington D.C.",
    "languages": [
      {
        "code": "en",
        "name": "English",
        "native": "English"
      }
    ],
    "country_flag": "https://www.geoipy.com/flags/us.svg",
    "country_flag_emoji": "🇺🇸",
    "country_flag_emoji_unicode": "U+1F1FA U+1F1F8",
    "calling_code": "1",
    "is_eu": false
  },
  "time_zone": {
    "id": "America/New_York",
    "current_time": "2024-09-19T03:58:13+03:00",
    "gmt_offset": -14400,
    "code": "EDT",
    "is_daylight_saving": true
  },
  "currency": {
    "code": "USD",
    "name": "US Dollar",
    "plural": "US dollars",
    "symbol": "$",
    "symbol_native": "$"
  },
  "connection": {
    "asn": 16509,
    "isp": "amazon.com Inc",
    "sld": "amazonaws",
    "tld": "com",
    "carrier": "amazon.com inc",
    "home": false,
    "organization_type": "Retail",
    "isic_code": "G4791",
    "naics_code": "004541"
  }
}
                            


API响应包含与位置、货币、时区和连接相关的详细数据。

错误代码

如果请求的资源不可用或API调用遇到问题,将返回JSON错误。这些错误始终伴随有错误代码和描述。

错误示例:当超过每月API请求限制时,将返回以下错误。
{
  "success": false,
  "error": {
    "code": 100,
    "type": "missing_access_key",
    "info": "No API Key was specified."
  }
}


代码 类型 信息
100 missing_access_key No API Key was specified.
101 invalid_access_key No API Key was specified or an invalid API Key was specified.
102 inactive_user The current user account is not active. User will be prompted to get in touch with Customer Support.
103 invalid_api_function The requested API endpoint does not exist.
104 usage_limit_reached The maximum allowed amount of monthly API requests has been reached.
105 function_access_restricted The current subscription plan does not support this API endpoint.
106 https_access_restricted The user's current subscription plan does not support HTTPS Encryption.
301 invalid_fields One or more invalid fields were specified using the fields parameter.
302 too_many_ips Too many IPs have been specified for the Bulk Lookup Endpoint. (max. 50)
303 batch_not_supported_on_plan The Bulk Lookup Endpoint is not supported on the current subscription plan
404 404_not_found The requested resource does not exist.

PHP(cURL)

//设置IP地址和API访问密钥
$ip = '18.191.200.108';
$key = 'veluihrPp9w0CekwtTlTo7TzaofQaIwp';

// 初始化CURL:
$ch = curl_init('https://www.geoipy.com/api/IPsInfo?ip='.$ip.'&key='.$key.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// 存储数据:
$json = curl_exec($ch );
curl_close($ch);

// 解码JSON响应:
$api_result = json_decode($json, true);

// 输出“location”内的“capital”对象:
echo $api_result['location']['capital'];

JavaScript(jQuery.ajax)

// 设置IP地址和API访问密钥
var ip = '18.191.200.108'
var key = 'veluihrPp9w0CekwtTlTo7TzaofQaIwp';

// 通过jQuery.ajax获取API结果
$.ajax({
url: 'https://www.geoipy.com/api/IPsInfo?ip=' + ip + '&key=' + key,
dataType: 'jsonp',
success: function(json) {

// 输出“location”内的“capital”对象
alert(json.location.capital);

}
});

C#

using System.Net.Http;
using Newtonsoft.Json.Linq;

// ...

// 设置IP地址和API访问密钥
string ip = "18.191.200.108";
string Key = "veluihrPp9w0CekwtTlTo7TzaofQaIwp";

// 初始化HttpClient实例
using (var httpClient = new HttpClient())
{
// 发送HTTP GET请求到指定的URL
var response = await httpClient.GetAsync($"https://www.geoipy.com/api/IPsInfo?ip={ip}&key={Key}");


// 检查响应是否成功
if (response.IsSuccessStatusCode)
{
// 将JSON响应读取为字符串
string jsonResponse = await response.Content.ReadAsStringAsync();

// 将JSON字符串反序列化为JObject
JObject apiResult = JObject.Parse(jsonResponse);

// 检索“location”对象内的“capital”对象
string capital = apiResult["location"]["capital"].ToString();

// 输出capital
Console.WriteLine(capital);
}
else
{
Console.WriteLine("在获取数据时发生错误");
}
}