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

Look up an IP address with the DB-IP free API

See more Geolocation Examples

Use the DB-IP v2 free service to retrieve country, state or province, and city without an API key. This example uses HTTPS, which returned a successful free lookup during verification on November 20, 2026. The provider documents a limit of 500 daily requests for the free service. Paid services provide additional fields and quotas.

Check errorCode before reading the location. Free results have a smaller field set, and the application should handle missing location values.

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"
$oUrl = ObjCreate("Chilkat.StringBuilder")
$oUrl.Append("https://api.db-ip.com/v2/free/")
$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("errorCode") = 1) Then
            ConsoleWrite($oJson.StringOf("errorCode") & @CRLF)
        EndIf

        If ($oJson.JsonTypeOf("error") = 1) Then
            ConsoleWrite($oJson.StringOf("error") & @CRLF)
        EndIf

    EndIf

    Exit
EndIf

If ($bParsed <> True) Then
    ConsoleWrite("Expected a JSON object in the lookup response." & @CRLF)
    Exit
EndIf

If (($oJson.HasMember("errorCode") = True) Or ($oJson.JsonTypeOf("error") = 1)) Then
    ConsoleWrite("The service could not complete the lookup." & @CRLF)
    If ($oJson.JsonTypeOf("errorCode") = 1) Then
        ConsoleWrite($oJson.StringOf("errorCode") & @CRLF)
    EndIf

    If ($oJson.JsonTypeOf("error") = 1) Then
        ConsoleWrite($oJson.StringOf("error") & @CRLF)
    EndIf

    Exit
EndIf

If (($oJson.JsonTypeOf("ipAddress") <> 1) Or ($oJson.StringOfEquals("ipAddress","",True) = True)) Then
    ConsoleWrite("The response did not contain the expected IP address." & @CRLF)
    Exit
EndIf

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

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

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

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