API do GeoIPy
Token de Acesso à API
Saída da API
{
"ip": "216.73.216.141",
"hostname": "216.73.216.141",
"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": "0",
"ip_routing_type": "fixed",
"connection_type": "cable",
"location": {
"geoname_id": 4509211,
"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": "2025-12-01T01:13:32+03:00",
"gmt_offset": -18000,
"code": "EST",
"is_daylight_saving": false
},
"currency": {
"code": "USD",
"name": "US Dollar",
"plural": "US dollars",
"symbol": "$",
"symbol_native": "$"
},
"connection": {
"asn": 16509,
"isp": "amazon.com Inc.",
"sld": "windstream",
"tld": "net",
"carrier": "amazon.com inc.",
"home": null,
"organization_type": null,
"isic_code": null,
"naics_code": null
}
}
Códigos de Erro
{
"success": false,
"error": {
"code": 100,
"type": "missing_access_key",
"info": "No API Key was specified."
}
}
| Código | Tipo | Informações |
|---|---|---|
| 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)
//defina o endereço IP e a chave de acesso à API
$ip = '216.73.216.141';
$key = 'veluihrPp9w0CekwtTlTo7TzaofQaIwp';
// Inicializar o CURL:
$ch = curl_init('https://www.geoipy.com/api/IPsInfo?ip='.$ip.'&key='.$key.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Armazenar os dados:
$json = curl_exec($ch);
curl_close($ch);
// Decodificar a resposta JSON:
$api_result = json_decode($json, true);
// Exibir o objeto "capital" dentro de "location"
echo $api_result['location']['capital'];
JavaScript (jQuery.ajax)
// defina o endereço IP e a chave de acesso à API
var ip = '216.73.216.141'
var key = 'veluihrPp9w0CekwtTlTo7TzaofQaIwp';
// Obter o resultado da API via jQuery.ajax
$.ajax({
url: 'https://www.geoipy.com/api/IPsInfo?ip=' + ip + '&key=' + key,
dataType: 'jsonp',
success: function(json) {
// Exibir o objeto "capital" dentro de "location"
alert(json.location.capital);
}
});
C#
using System.Net.Http;
using Newtonsoft.Json.Linq;
// ...
// defina o endereço IP e a chave de acesso à API
string ip = "216.73.216.141";
string Key = "veluihrPp9w0CekwtTlTo7TzaofQaIwp";
// Inicializar uma instância HttpClient
using (var httpClient = new HttpClient())
{
// Enviar uma solicitação HTTP GET para a URL especificada
var response = await httpClient.GetAsync($"https://www.geoipy.com/api/IPsInfo?ip={ip}&key={Key}");
// Verificar se a resposta foi bem-sucedida
if (response.IsSuccessStatusCode)
{
// Ler a resposta JSON como uma string
string jsonResponse = await response.Content.ReadAsStringAsync();
// Desserializar a string JSON em um JObject
JObject apiResult = JObject.Parse(jsonResponse);
// Recuperar o objeto "capital" dentro do objeto "location"
string capital = apiResult["location"]["capital"].ToString();
// Exibir a capital
Console.WriteLine(capital);
}
else
{
Console.WriteLine("Ocorreu um erro ao buscar os dados");
}
}