Unicode C++
Unicode C++
ipinfo.io IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the ipinfo.io API.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
http.put_Login(L"ACCESS_TOKEN");
http.put_Password(L"");
http.put_Accept(L"application/json");
// Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address)
const wchar_t *jsonStr = http.quickGetStr(L"https://ipinfo.io/149.250.207.170");
if (http.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkJsonObjectW json;
json.put_EmitCompact(false);
success = json.Load(jsonStr);
wprintf(L"%s\n",json.emit());
// Sample output:
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// Note: This is the output for the free trial account.
//
// {
// "ip": "149.250.207.170",
// "city": "",
// "region": "",
// "country": "DE",
// "loc": "51.2993,9.4910",
// "org": "AS15854 EntServ Deutschland GmbH"
// }
// A full response would look like this:
// {
// "ip": "66.87.125.72",
// "hostname": "66-87-125-72.pools.spcsdns.net",
// "city": "Southbridge",
// "region": "Massachusetts",
// "country": "US",
// "loc": "42.0707,-72.0440",
// "postal": "01550",
// "asn": {
// "asn": "AS10507",
// "name": "Sprint Personal Communications Systems",
// "domain": "spcsdns.net",
// "route": "66.87.125.0/24",
// "type": "isp"
// },
// "company": {
// "name": "Sprint Springfield POP",
// "domain": "sprint.com",
// "type": "isp"
// },
// "carrier": {
// "name": "Sprint",
// "mcc": "310",
// "mnc": "120"
// }
// }
//
const wchar_t *ip = 0;
const wchar_t *hostname = 0;
const wchar_t *city = 0;
const wchar_t *region = 0;
const wchar_t *country = 0;
const wchar_t *loc = 0;
const wchar_t *postal = 0;
const wchar_t *asnAsn = 0;
const wchar_t *asnName = 0;
const wchar_t *asnDomain = 0;
const wchar_t *asnRoute = 0;
const wchar_t *asnType = 0;
const wchar_t *companyName = 0;
const wchar_t *companyDomain = 0;
const wchar_t *companyType = 0;
const wchar_t *carrierName = 0;
const wchar_t *carrierMcc = 0;
const wchar_t *carrierMnc = 0;
ip = json.stringOf(L"ip");
hostname = json.stringOf(L"hostname");
city = json.stringOf(L"city");
region = json.stringOf(L"region");
country = json.stringOf(L"country");
loc = json.stringOf(L"loc");
postal = json.stringOf(L"postal");
asnAsn = json.stringOf(L"asn.asn");
asnName = json.stringOf(L"asn.name");
asnDomain = json.stringOf(L"asn.domain");
asnRoute = json.stringOf(L"asn.route");
asnType = json.stringOf(L"asn.type");
companyName = json.stringOf(L"company.name");
companyDomain = json.stringOf(L"company.domain");
companyType = json.stringOf(L"company.type");
carrierName = json.stringOf(L"carrier.name");
carrierMcc = json.stringOf(L"carrier.mcc");
carrierMnc = json.stringOf(L"carrier.mnc");
}