Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

Look up an IP address with IP2Location.io

See more Geolocation Examples

Look up a public IPv4 or IPv6 address. The sample runs keyless. To use your account allowance, set apiKey and Chilkat will send it as a Bearer token. IP2Location.io recommends header authentication and also accepts its older key query parameter.

Keyless requests have a daily allowance. Registered plans have their own quotas and field availability. Check the provider’s current limits. An HTTP 401 with error 10000 can indicate an invalid key or an exhausted free allowance. Coordinates can default to the capital city when a city is unknown. The returned time_zone is a UTC offset.

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.

Service documentation

Chilkat AutoIt Downloads

AutoIt
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"
;  Leave empty for keyless evaluation, or set the API key from your account.
Local $sApiKey = ""
If ($sApiKey <> "") Then
    $oHttp.AuthToken = $sApiKey
EndIf

$oParameters = ObjCreate("Chilkat.JsonObject")
$oParameters.UpdateString("ip",$sIpAddress)
$oParameters.UpdateString("format","json")
$oResponse = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpParams("GET","https://api.ip2location.io/",$oParameters,$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.error_message") = 1) Then
            ConsoleWrite($oJson.StringOf("error.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.error_message") = 1) Then
        ConsoleWrite($oJson.StringOf("error.error_message") & @CRLF)
    EndIf

    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("country_name") = 1) And ($oJson.StringOfEquals("country_name","",True) <> True)) Then
    ConsoleWrite("Country: " & $oJson.StringOf("country_name") & @CRLF)
Else
    ConsoleWrite("Country: unavailable" & @CRLF)
EndIf

If (($oJson.JsonTypeOf("country_code") = 1) And ($oJson.StringOfEquals("country_code","",True) <> True)) Then
    ConsoleWrite("Country code: " & $oJson.StringOf("country_code") & @CRLF)
Else
    ConsoleWrite("Country code: unavailable" & @CRLF)
EndIf

If (($oJson.JsonTypeOf("region_name") = 1) And ($oJson.StringOfEquals("region_name","",True) <> True)) Then
    ConsoleWrite("Region: " & $oJson.StringOf("region_name") & @CRLF)
Else
    ConsoleWrite("Region: unavailable" & @CRLF)
EndIf

If (($oJson.JsonTypeOf("city_name") = 1) And ($oJson.StringOfEquals("city_name","",True) <> True)) Then
    ConsoleWrite("City: " & $oJson.StringOf("city_name") & @CRLF)
Else
    ConsoleWrite("City: unavailable" & @CRLF)
EndIf

If (($oJson.JsonTypeOf("time_zone") = 1) And ($oJson.StringOfEquals("time_zone","",True) <> True)) Then
    ConsoleWrite("UTC offset: " & $oJson.StringOf("time_zone") & @CRLF)
Else
    ConsoleWrite("UTC offset: unavailable" & @CRLF)
EndIf

;  Missing coordinates stay unavailable. A numeric zero is a valid coordinate.
If (($oJson.JsonTypeOf("latitude") = 2) And ($oJson.JsonTypeOf("longitude") = 2)) Then
    ConsoleWrite("Coordinates: " & $oJson.StringOf("latitude") & ", " & $oJson.StringOf("longitude") & @CRLF)
Else
    ConsoleWrite("Coordinates: unavailable" & @CRLF)
EndIf