PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
jsonStr.s = CkHttp::ckQuickGetStr(http,"https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY")
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
ProcedureReturn
EndIf
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::setCkEmitCompact(json, 0)
success = CkJsonObject::ckLoad(json,jsonStr)
Debug CkJsonObject::ckEmit(json)
; 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"
; }
ip.s
is_eu.i
city.s
region.s
region_code.s
country_name.s
country_code.s
continent_name.s
continent_code.s
latitude.s
longitude.s
asn.s
organisation.s
postal.s
calling_code.s
flag.s
emoji_flag.s
emoji_unicode.s
currencyName.s
currencyCode.s
currencySymbol.s
currencyNative.s
currencyPlural.s
time_zoneName.s
time_zoneAbbr.s
time_zoneOffset.s
time_zoneIs_dst.i
time_zoneCurrent_time.s
threatIs_tor.i
threatIs_proxy.i
threatIs_anonymous.i
threatIs_known_attacker.i
threatIs_known_abuser.i
threatIs_threat.i
threatIs_bogon.i
count.s
i.i
count_i.i
name.s
native.s
ip = CkJsonObject::ckStringOf(json,"ip")
is_eu = CkJsonObject::ckBoolOf(json,"is_eu")
city = CkJsonObject::ckStringOf(json,"city")
region = CkJsonObject::ckStringOf(json,"region")
region_code = CkJsonObject::ckStringOf(json,"region_code")
country_name = CkJsonObject::ckStringOf(json,"country_name")
country_code = CkJsonObject::ckStringOf(json,"country_code")
continent_name = CkJsonObject::ckStringOf(json,"continent_name")
continent_code = CkJsonObject::ckStringOf(json,"continent_code")
latitude = CkJsonObject::ckStringOf(json,"latitude")
longitude = CkJsonObject::ckStringOf(json,"longitude")
asn = CkJsonObject::ckStringOf(json,"asn")
organisation = CkJsonObject::ckStringOf(json,"organisation")
postal = CkJsonObject::ckStringOf(json,"postal")
calling_code = CkJsonObject::ckStringOf(json,"calling_code")
flag = CkJsonObject::ckStringOf(json,"flag")
emoji_flag = CkJsonObject::ckStringOf(json,"emoji_flag")
emoji_unicode = CkJsonObject::ckStringOf(json,"emoji_unicode")
currencyName = CkJsonObject::ckStringOf(json,"currency.name")
currencyCode = CkJsonObject::ckStringOf(json,"currency.code")
currencySymbol = CkJsonObject::ckStringOf(json,"currency.symbol")
currencyNative = CkJsonObject::ckStringOf(json,"currency.native")
currencyPlural = CkJsonObject::ckStringOf(json,"currency.plural")
time_zoneName = CkJsonObject::ckStringOf(json,"time_zone.name")
time_zoneAbbr = CkJsonObject::ckStringOf(json,"time_zone.abbr")
time_zoneOffset = CkJsonObject::ckStringOf(json,"time_zone.offset")
time_zoneIs_dst = CkJsonObject::ckBoolOf(json,"time_zone.is_dst")
time_zoneCurrent_time = CkJsonObject::ckStringOf(json,"time_zone.current_time")
threatIs_tor = CkJsonObject::ckBoolOf(json,"threat.is_tor")
threatIs_proxy = CkJsonObject::ckBoolOf(json,"threat.is_proxy")
threatIs_anonymous = CkJsonObject::ckBoolOf(json,"threat.is_anonymous")
threatIs_known_attacker = CkJsonObject::ckBoolOf(json,"threat.is_known_attacker")
threatIs_known_abuser = CkJsonObject::ckBoolOf(json,"threat.is_known_abuser")
threatIs_threat = CkJsonObject::ckBoolOf(json,"threat.is_threat")
threatIs_bogon = CkJsonObject::ckBoolOf(json,"threat.is_bogon")
count = CkJsonObject::ckStringOf(json,"count")
i = 0
count_i = CkJsonObject::ckSizeOfArray(json,"languages")
While i < count_i
CkJsonObject::setCkI(json, i)
name = CkJsonObject::ckStringOf(json,"languages[i].name")
native = CkJsonObject::ckStringOf(json,"languages[i].native")
i = i + 1
Wend
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure