Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL cJsonStr
LOCAL oJson
LOCAL cIp
LOCAL nIs_eu
LOCAL cCity
LOCAL cRegion
LOCAL cRegion_code
LOCAL cCountry_name
LOCAL cCountry_code
LOCAL cContinent_name
LOCAL cContinent_code
LOCAL cLatitude
LOCAL cLongitude
LOCAL cAsn
LOCAL cOrganisation
LOCAL cPostal
LOCAL cCalling_code
LOCAL cFlag
LOCAL cEmoji_flag
LOCAL cEmoji_unicode
LOCAL cCurrencyName
LOCAL cCurrencyCode
LOCAL cCurrencySymbol
LOCAL cCurrencyNative
LOCAL cCurrencyPlural
LOCAL cTime_zoneName
LOCAL cTime_zoneAbbr
LOCAL cTime_zoneOffset
LOCAL nTime_zoneIs_dst
LOCAL cTime_zoneCurrent_time
LOCAL nThreatIs_tor
LOCAL nThreatIs_proxy
LOCAL nThreatIs_anonymous
LOCAL nThreatIs_known_attacker
LOCAL nThreatIs_known_abuser
LOCAL nThreatIs_threat
LOCAL nThreatIs_bogon
LOCAL cCount
LOCAL i
LOCAL nCount_i
LOCAL cName
LOCAL cNative
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
cJsonStr := oHttp:QuickGetStr("https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY")
IF (oHttp:LastMethodSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
RETURN
ENDIF
oJson := CreateObject("Chilkat.JsonObject")
oJson:EmitCompact := 0
nSuccess := oJson:Load(cJsonStr)
? oJson: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"
// }
cIp := oJson:StringOf("ip")
nIs_eu := oJson:BoolOf("is_eu")
cCity := oJson:StringOf("city")
cRegion := oJson:StringOf("region")
cRegion_code := oJson:StringOf("region_code")
cCountry_name := oJson:StringOf("country_name")
cCountry_code := oJson:StringOf("country_code")
cContinent_name := oJson:StringOf("continent_name")
cContinent_code := oJson:StringOf("continent_code")
cLatitude := oJson:StringOf("latitude")
cLongitude := oJson:StringOf("longitude")
cAsn := oJson:StringOf("asn")
cOrganisation := oJson:StringOf("organisation")
cPostal := oJson:StringOf("postal")
cCalling_code := oJson:StringOf("calling_code")
cFlag := oJson:StringOf("flag")
cEmoji_flag := oJson:StringOf("emoji_flag")
cEmoji_unicode := oJson:StringOf("emoji_unicode")
cCurrencyName := oJson:StringOf("currency.name")
cCurrencyCode := oJson:StringOf("currency.code")
cCurrencySymbol := oJson:StringOf("currency.symbol")
cCurrencyNative := oJson:StringOf("currency.native")
cCurrencyPlural := oJson:StringOf("currency.plural")
cTime_zoneName := oJson:StringOf("time_zone.name")
cTime_zoneAbbr := oJson:StringOf("time_zone.abbr")
cTime_zoneOffset := oJson:StringOf("time_zone.offset")
nTime_zoneIs_dst := oJson:BoolOf("time_zone.is_dst")
cTime_zoneCurrent_time := oJson:StringOf("time_zone.current_time")
nThreatIs_tor := oJson:BoolOf("threat.is_tor")
nThreatIs_proxy := oJson:BoolOf("threat.is_proxy")
nThreatIs_anonymous := oJson:BoolOf("threat.is_anonymous")
nThreatIs_known_attacker := oJson:BoolOf("threat.is_known_attacker")
nThreatIs_known_abuser := oJson:BoolOf("threat.is_known_abuser")
nThreatIs_threat := oJson:BoolOf("threat.is_threat")
nThreatIs_bogon := oJson:BoolOf("threat.is_bogon")
cCount := oJson:StringOf("count")
i := 0
nCount_i := oJson:SizeOfArray("languages")
DO WHILE i < nCount_i
oJson:I := i
cName := oJson:StringOf("languages[i].name")
cNative := oJson:StringOf("languages[i].native")
i := i + 1
ENDDO
oHttp:destroy()
oJson:destroy()