AutoIt
AutoIt
ipstack.com IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the ipstack.com REST API.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
; Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address)
Local $sJsonStr = $oHttp.QuickGetStr("http://api.ipstack.com/149.250.207.170?access_key=YOUR_ACCESS_KEY")
If ($oHttp.LastMethodSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.EmitCompact = False
$bSuccess = $oJson.Load($sJsonStr)
ConsoleWrite($oJson.Emit() & @CRLF)
; Sample output:
; Use this online tool to generate parsing code from sample JSON:
; Generate Parsing Code from JSON
; {
; "ip": "149.250.207.170",
; "type": "ipv4",
; "continent_code": "EU",
; "continent_name": "Europe",
; "country_code": "DE",
; "country_name": "Germany",
; "region_code": null,
; "region_name": null,
; "city": null,
; "zip": null,
; "latitude": 51.2993,
; "longitude": 9.491,
; "location": {
; "geoname_id": null,
; "capital": "Berlin",
; "languages": [
; {
; "code": "de",
; "name": "German",
; "native": "Deutsch"
; }
; ],
; "country_flag": "http:\/\/assets.ipstack.com\/flags\/de.svg",
; "country_flag_emoji": "\ud83c\udde9\ud83c\uddea",
; "country_flag_emoji_unicode": "U+1F1E9 U+1F1EA",
; "calling_code": "49",
; "is_eu": true
; }
; }
Local $sIp
Local $sV_type
Local $sContinent_code
Local $sContinent_name
Local $sCountry_code
Local $sCountry_name
Local $sRegion_code
Local $sRegion_name
Local $sCity
Local $sZip
Local $sLatitude
Local $sLongitude
Local $sLocationGeoname_id
Local $sLocationCapital
Local $sLocationCountry_flag
Local $sLocationCountry_flag_emoji
Local $sLocationCountry_flag_emoji_unicode
Local $sLocationCalling_code
Local $bLocationIs_eu
Local $i
Local $iCount_i
Local $sCode
Local $sName
Local $sNative
$sIp = $oJson.StringOf("ip")
$sV_type = $oJson.StringOf("type")
$sContinent_code = $oJson.StringOf("continent_code")
$sContinent_name = $oJson.StringOf("continent_name")
$sCountry_code = $oJson.StringOf("country_code")
$sCountry_name = $oJson.StringOf("country_name")
$sRegion_code = $oJson.StringOf("region_code")
$sRegion_name = $oJson.StringOf("region_name")
$sCity = $oJson.StringOf("city")
$sZip = $oJson.StringOf("zip")
$sLatitude = $oJson.StringOf("latitude")
$sLongitude = $oJson.StringOf("longitude")
$sLocationGeoname_id = $oJson.StringOf("location.geoname_id")
$sLocationCapital = $oJson.StringOf("location.capital")
$sLocationCountry_flag = $oJson.StringOf("location.country_flag")
$sLocationCountry_flag_emoji = $oJson.StringOf("location.country_flag_emoji")
$sLocationCountry_flag_emoji_unicode = $oJson.StringOf("location.country_flag_emoji_unicode")
$sLocationCalling_code = $oJson.StringOf("location.calling_code")
$bLocationIs_eu = $oJson.BoolOf("location.is_eu")
$i = 0
$iCount_i = $oJson.SizeOfArray("location.languages")
While $i < $iCount_i
$oJson.I = $i
$sCode = $oJson.StringOf("location.languages[i].code")
$sName = $oJson.StringOf("location.languages[i].name")
$sNative = $oJson.StringOf("location.languages[i].native")
$i = $i + 1
Wend