Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL lcJsonStr
LOCAL loJson
LOCAL lcIp
LOCAL lnIs_eu
LOCAL lcCity
LOCAL lcRegion
LOCAL lcRegion_code
LOCAL lcCountry_name
LOCAL lcCountry_code
LOCAL lcContinent_name
LOCAL lcContinent_code
LOCAL lcLatitude
LOCAL lcLongitude
LOCAL lcAsn
LOCAL lcOrganisation
LOCAL lcPostal
LOCAL lcCalling_code
LOCAL lcFlag
LOCAL lcEmoji_flag
LOCAL lcEmoji_unicode
LOCAL lcCurrencyName
LOCAL lcCurrencyCode
LOCAL lcCurrencySymbol
LOCAL lcCurrencyNative
LOCAL lcCurrencyPlural
LOCAL lcTime_zoneName
LOCAL lcTime_zoneAbbr
LOCAL lcTime_zoneOffset
LOCAL lnTime_zoneIs_dst
LOCAL lcTime_zoneCurrent_time
LOCAL lnThreatIs_tor
LOCAL lnThreatIs_proxy
LOCAL lnThreatIs_anonymous
LOCAL lnThreatIs_known_attacker
LOCAL lnThreatIs_known_abuser
LOCAL lnThreatIs_threat
LOCAL lnThreatIs_bogon
LOCAL lcCount
LOCAL i
LOCAL lnCount_i
LOCAL lcName
LOCAL lcNative
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = CreateObject('Chilkat.Http')
lcJsonStr = loHttp.QuickGetStr("https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY")
IF (loHttp.LastMethodSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
CANCEL
ENDIF
loJson = CreateObject('Chilkat.JsonObject')
loJson.EmitCompact = 0
lnSuccess = 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")
lnIs_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")
lnTime_zoneIs_dst = loJson.BoolOf("time_zone.is_dst")
lcTime_zoneCurrent_time = loJson.StringOf("time_zone.current_time")
lnThreatIs_tor = loJson.BoolOf("threat.is_tor")
lnThreatIs_proxy = loJson.BoolOf("threat.is_proxy")
lnThreatIs_anonymous = loJson.BoolOf("threat.is_anonymous")
lnThreatIs_known_attacker = loJson.BoolOf("threat.is_known_attacker")
lnThreatIs_known_abuser = loJson.BoolOf("threat.is_known_abuser")
lnThreatIs_threat = loJson.BoolOf("threat.is_threat")
lnThreatIs_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