AutoIt Requires Chilkat v11.0.0+
AutoIt
Look up an IP location with IPinfo Core
See more Geolocation Examples
Use an IPinfo token with Core, Plus, or Max access. The current api.ipinfo.io/lookup/ endpoint returns location fields inside geo and network fields inside as. Authenticate with a Bearer token.
IPinfo continues to support its older ipinfo.io API for existing integrations. This example uses the current Core response structure. The free Lite API uses /lite/ and a different, country-level response. Choose the endpoint and parser for your subscription.
IP geolocation estimates a network location. VPNs, mobile gateways, and anycast routing can affect the result. City and coordinate fields can be missing or approximate. The sample address 8.8.8.8 is a public DNS address used to demonstrate the request.
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
; Use a public IP address. Provider results can change as their databases are updated.
Local $sIpAddress = "8.8.8.8"
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.RequireSslCertVerify = True
$oHttp.ConnectTimeout = 10
$oHttp.ReadTimeout = 30
$oHttp.Accept = "application/json"
$oHttp.AuthToken = "IPINFO_TOKEN"
$oUrl = ObjCreate("Chilkat.StringBuilder")
$oUrl.Append("https://api.ipinfo.io/lookup/")
$oUrl.Append($oHttp.UrlEncode($sIpAddress))
$oResponse = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpNoBody("GET",$oUrl.GetAsString(),$oResponse)
If ($oResponse.StatusCode = 0) Then
; Request diagnostics can contain an API key. Report transport failure without logging credentials.
ConsoleWrite("No HTTP response. Check connectivity, DNS, and TLS configuration." & @CRLF)
Exit
EndIf
$oJson = ObjCreate("Chilkat.JsonObject")
Local $bParsed = $oJson.Load($oResponse.BodyStr)
If (($bSuccess <> True) Or ($oResponse.StatusCode < 200) Or ($oResponse.StatusCode >= 300)) Then
ConsoleWrite("Lookup failed. HTTP " & $oResponse.StatusCode & @CRLF)
If ($bParsed = True) Then
If ($oJson.JsonTypeOf("error.title") = 1) Then
ConsoleWrite($oJson.StringOf("error.title") & @CRLF)
EndIf
If ($oJson.JsonTypeOf("error.message") = 1) Then
ConsoleWrite($oJson.StringOf("error.message") & @CRLF)
EndIf
EndIf
Exit
EndIf
If ($bParsed <> True) Then
ConsoleWrite("Expected a JSON object in the lookup response." & @CRLF)
Exit
EndIf
If (($oJson.JsonTypeOf("error") = 3)) Then
ConsoleWrite("The service could not complete the lookup." & @CRLF)
If ($oJson.JsonTypeOf("error.title") = 1) Then
ConsoleWrite($oJson.StringOf("error.title") & @CRLF)
EndIf
If ($oJson.JsonTypeOf("error.message") = 1) Then
ConsoleWrite($oJson.StringOf("error.message") & @CRLF)
EndIf
Exit
EndIf
If (($oJson.JsonTypeOf("bogon") = 5) And ($oJson.BoolOf("bogon") = True)) Then
ConsoleWrite("This is a reserved or otherwise non-public IP address." & @CRLF)
Exit
EndIf
If (($oJson.JsonTypeOf("ip") <> 1) Or ($oJson.StringOfEquals("ip","",True) = True)) Then
ConsoleWrite("The response did not contain the expected IP address." & @CRLF)
Exit
EndIf
ConsoleWrite("IP address: " & $oJson.StringOf("ip") & @CRLF)
If (($oJson.JsonTypeOf("geo.country") = 1) And ($oJson.StringOfEquals("geo.country","",True) <> True)) Then
ConsoleWrite("Country: " & $oJson.StringOf("geo.country") & @CRLF)
Else
ConsoleWrite("Country: unavailable" & @CRLF)
EndIf
If (($oJson.JsonTypeOf("geo.country_code") = 1) And ($oJson.StringOfEquals("geo.country_code","",True) <> True)) Then
ConsoleWrite("Country code: " & $oJson.StringOf("geo.country_code") & @CRLF)
Else
ConsoleWrite("Country code: unavailable" & @CRLF)
EndIf
If (($oJson.JsonTypeOf("geo.region") = 1) And ($oJson.StringOfEquals("geo.region","",True) <> True)) Then
ConsoleWrite("Region: " & $oJson.StringOf("geo.region") & @CRLF)
Else
ConsoleWrite("Region: unavailable" & @CRLF)
EndIf
If (($oJson.JsonTypeOf("geo.city") = 1) And ($oJson.StringOfEquals("geo.city","",True) <> True)) Then
ConsoleWrite("City: " & $oJson.StringOf("geo.city") & @CRLF)
Else
ConsoleWrite("City: unavailable" & @CRLF)
EndIf
If (($oJson.JsonTypeOf("geo.timezone") = 1) And ($oJson.StringOfEquals("geo.timezone","",True) <> True)) Then
ConsoleWrite("Time zone: " & $oJson.StringOf("geo.timezone") & @CRLF)
Else
ConsoleWrite("Time zone: unavailable" & @CRLF)
EndIf
; Missing coordinates stay unavailable. A numeric zero is a valid coordinate.
If (($oJson.JsonTypeOf("geo.latitude") = 2) And ($oJson.JsonTypeOf("geo.longitude") = 2)) Then
ConsoleWrite("Coordinates: " & $oJson.StringOf("geo.latitude") & ", " & $oJson.StringOf("geo.longitude") & @CRLF)
Else
ConsoleWrite("Coordinates: unavailable" & @CRLF)
EndIf
If (($oJson.JsonTypeOf("as.asn") = 1) And ($oJson.StringOfEquals("as.asn","",True) <> True)) Then
ConsoleWrite("ASN: " & $oJson.StringOf("as.asn") & @CRLF)
Else
ConsoleWrite("ASN: unavailable" & @CRLF)
EndIf
If (($oJson.JsonTypeOf("as.name") = 1) And ($oJson.StringOfEquals("as.name","",True) <> True)) Then
ConsoleWrite("Network organization: " & $oJson.StringOf("as.name") & @CRLF)
Else
ConsoleWrite("Network organization: unavailable" & @CRLF)
EndIf