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

Geolocation of IP Address

See more REST Examples

Retrieve country, state or province, and city for a public IP address using the DB-IP v2 free JSON API. This replaces the retired freegeoip.net request and the historical two-service comparison. The sample sends one HTTPS request, checks transport and service errors, and reads the returned fields.

DB-IP documents 500 daily requests for its free service. Its free HTTPS endpoint returned a successful lookup during verification on November 20, 2026. For other providers and authenticated services, see the Geolocation examples.

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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
'  Use a public IP address. Provider results can change as their databases are updated.
ipAddress = "8.8.8.8"
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.ConnectTimeout = 10
http.ReadTimeout = 30
http.Accept = "application/json"
set url = Server.CreateObject("Chilkat.StringBuilder")
success = url.Append("https://api.db-ip.com/v2/free/")
success = url.Append(http.UrlEncode(ipAddress))
ERROR: ASP example cannot use request or response as a variable name.
success = http.HttpNoBody("GET",url.GetAsString(),response)
If (response.StatusCode = 0) Then
    '  Request diagnostics can contain an API key. Report transport failure without logging credentials.
    Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Check connectivity, DNS, and TLS configuration.") & "</pre>"
    Response.End
End If

set json = Server.CreateObject("Chilkat.JsonObject")
parsed = json.Load(response.BodyStr)
If ((success <> 1) Or (response.StatusCode < 200) Or (response.StatusCode >= 300)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Lookup failed. HTTP " & response.StatusCode) & "</pre>"
    If (parsed = 1) Then
        If (json.JsonTypeOf("errorCode") = 1) Then
            Response.Write "<pre>" & Server.HTMLEncode( json.StringOf("errorCode")) & "</pre>"
        End If

        If (json.JsonTypeOf("error") = 1) Then
            Response.Write "<pre>" & Server.HTMLEncode( json.StringOf("error")) & "</pre>"
        End If

    End If

    Response.End
End If

If (parsed <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON object in the lookup response.") & "</pre>"
    Response.End
End If

If ((json.HasMember("errorCode") = 1) Or (json.JsonTypeOf("error") = 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "The service could not complete the lookup.") & "</pre>"
    If (json.JsonTypeOf("errorCode") = 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( json.StringOf("errorCode")) & "</pre>"
    End If

    If (json.JsonTypeOf("error") = 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( json.StringOf("error")) & "</pre>"
    End If

    Response.End
End If

If ((json.JsonTypeOf("ipAddress") <> 1) Or (json.StringOfEquals("ipAddress","",1) = 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "The response did not contain the expected IP address.") & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "IP address: " & json.StringOf("ipAddress")) & "</pre>"
If ((json.JsonTypeOf("countryName") = 1) And (json.StringOfEquals("countryName","",1) <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Country: " & json.StringOf("countryName")) & "</pre>"
Else
    Response.Write "<pre>" & Server.HTMLEncode( "Country: unavailable") & "</pre>"
End If

If ((json.JsonTypeOf("countryCode") = 1) And (json.StringOfEquals("countryCode","",1) <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Country code: " & json.StringOf("countryCode")) & "</pre>"
Else
    Response.Write "<pre>" & Server.HTMLEncode( "Country code: unavailable") & "</pre>"
End If

If ((json.JsonTypeOf("stateProv") = 1) And (json.StringOfEquals("stateProv","",1) <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "State or province: " & json.StringOf("stateProv")) & "</pre>"
Else
    Response.Write "<pre>" & Server.HTMLEncode( "State or province: unavailable") & "</pre>"
End If

If ((json.JsonTypeOf("city") = 1) And (json.StringOfEquals("city","",1) <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "City: " & json.StringOf("city")) & "</pre>"
Else
    Response.Write "<pre>" & Server.HTMLEncode( "City: unavailable") & "</pre>"
End If


%>
</body>
</html>