Sample code for 30+ languages & platforms
Lianja

ipdata.co IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the ipdata.co API.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loHttp = createobject("CkHttp")

lcJsonStr = loHttp.QuickGetStr("https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY")
if (loHttp.LastMethodSuccess = .F.) then
    ? loHttp.LastErrorText
    release loHttp
    return
endif

loJson = createobject("CkJsonObject")
loJson.EmitCompact = .F.
llSuccess = loJson.Load(lcJsonStr)

? loJson.Emit()

// Sample output:
// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

// {
//   "ip": "149.250.207.170",
//   "is_eu": true,
//   "city": null,
//   "region": null,
//   "region_code": null,
//   "country_name": "Germany",
//   "country_code": "DE",
//   "continent_name": "Europe",
//   "continent_code": "EU",
//   "latitude": 51.2993,
//   "longitude": 9.491,
//   "asn": "AS15854",
//   "organisation": "EntServ Deutschland GmbH",
//   "postal": null,
//   "calling_code": "49",
//   "flag": "https://ipdata.co/flags/de.png",
//   "emoji_flag": "\ud83c\udde9\ud83c\uddea",
//   "emoji_unicode": "U+1F1E9 U+1F1EA",
//   "languages": [
//     {
//       "name": "German",
//       "native": "Deutsch"
//     }
//   ],
//   "currency": {
//     "name": "Euro",
//     "code": "EUR",
//     "symbol": "\u20ac",
//     "native": "\u20ac",
//     "plural": "euros"
//   },
//   "time_zone": {
//     "name": "Europe/Berlin",
//     "abbr": "CEST",
//     "offset": "+0200",
//     "is_dst": true,
//     "current_time": "2019-04-20T23:54:30.715507+02:00"
//   },
//   "threat": {
//     "is_tor": false,
//     "is_proxy": false,
//     "is_anonymous": false,
//     "is_known_attacker": false,
//     "is_known_abuser": false,
//     "is_threat": false,
//     "is_bogon": false
//   },
//   "count": "2"
// }

lcIp = loJson.StringOf("ip")
llIs_eu = loJson.BoolOf("is_eu")
lcCity = loJson.StringOf("city")
lcRegion = loJson.StringOf("region")
lcRegion_code = loJson.StringOf("region_code")
lcCountry_name = loJson.StringOf("country_name")
lcCountry_code = loJson.StringOf("country_code")
lcContinent_name = loJson.StringOf("continent_name")
lcContinent_code = loJson.StringOf("continent_code")
lcLatitude = loJson.StringOf("latitude")
lcLongitude = loJson.StringOf("longitude")
lcAsn = loJson.StringOf("asn")
lcOrganisation = loJson.StringOf("organisation")
lcPostal = loJson.StringOf("postal")
lcCalling_code = loJson.StringOf("calling_code")
lcFlag = loJson.StringOf("flag")
lcEmoji_flag = loJson.StringOf("emoji_flag")
lcEmoji_unicode = loJson.StringOf("emoji_unicode")
lcCurrencyName = loJson.StringOf("currency.name")
lcCurrencyCode = loJson.StringOf("currency.code")
lcCurrencySymbol = loJson.StringOf("currency.symbol")
lcCurrencyNative = loJson.StringOf("currency.native")
lcCurrencyPlural = loJson.StringOf("currency.plural")
lcTime_zoneName = loJson.StringOf("time_zone.name")
lcTime_zoneAbbr = loJson.StringOf("time_zone.abbr")
lcTime_zoneOffset = loJson.StringOf("time_zone.offset")
llTime_zoneIs_dst = loJson.BoolOf("time_zone.is_dst")
lcTime_zoneCurrent_time = loJson.StringOf("time_zone.current_time")
llThreatIs_tor = loJson.BoolOf("threat.is_tor")
llThreatIs_proxy = loJson.BoolOf("threat.is_proxy")
llThreatIs_anonymous = loJson.BoolOf("threat.is_anonymous")
llThreatIs_known_attacker = loJson.BoolOf("threat.is_known_attacker")
llThreatIs_known_abuser = loJson.BoolOf("threat.is_known_abuser")
llThreatIs_threat = loJson.BoolOf("threat.is_threat")
llThreatIs_bogon = loJson.BoolOf("threat.is_bogon")
lcCount = loJson.StringOf("count")
i = 0
lnCount_i = loJson.SizeOfArray("languages")
do while i < lnCount_i
    loJson.I = i
    lcName = loJson.StringOf("languages[i].name")
    lcNative = loJson.StringOf("languages[i].native")
    i = i + 1
enddo


release loHttp
release loJson