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

Look up an IP address with ipdata

See more Geolocation Examples

Use an ipdata API key to request a public IPv4 or IPv6 address. The key is encoded as the api-key query parameter. The example displays location fields and the optional ASN object using its current nested structure. Data access and quotas depend on the account plan.

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"
Local $sApiKey = "YOUR_API_KEY"
$oUrl = ObjCreate("Chilkat.StringBuilder")
$oUrl.Append("https://api.ipdata.co/")
$oUrl.Append($oHttp.UrlEncode($sIpAddress))
$oParameters = ObjCreate("Chilkat.JsonObject")
$oParameters.UpdateString("api-key",$sApiKey)
$oResponse = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpParams("GET",$oUrl.GetAsString(),$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("message") = 1) Then
            ConsoleWrite($oJson.StringOf("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("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") = 1) And ($oJson.StringOfEquals("region","",True) <> True)) Then
    ConsoleWrite("Region: " & $oJson.StringOf("region") & @CRLF)
Else
    ConsoleWrite("Region: 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

If (($oJson.JsonTypeOf("time_zone.name") = 1) And ($oJson.StringOfEquals("time_zone.name","",True) <> True)) Then
    ConsoleWrite("Time zone: " & $oJson.StringOf("time_zone.name") & @CRLF)
Else
    ConsoleWrite("Time zone: 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

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

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