Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL lcIpAddress
LOCAL loHttp
LOCAL loUrl
LOCAL loResponse
LOCAL loJson
LOCAL lnParsed
lnSuccess = 0
* Assumes Chilkat is unlocked. See Global Unlock Sample.
* Use a public IP address. Provider results can change as their databases are updated.
lcIpAddress = "8.8.8.8"
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
loHttp.ConnectTimeout = 10
loHttp.ReadTimeout = 30
loHttp.Accept = "application/json"
loHttp.AuthToken = "IPINFO_TOKEN"
loUrl = CreateObject('Chilkat.StringBuilder')
loUrl.Append("https://api.ipinfo.io/lookup/")
loUrl.Append(loHttp.UrlEncode(lcIpAddress))
loResponse = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpNoBody("GET",loUrl.GetAsString(),loResponse)
IF (loResponse.StatusCode = 0) THEN
* Request diagnostics can contain an API key. Report transport failure without logging credentials.
? "No HTTP response. Check connectivity, DNS, and TLS configuration."
RELEASE loHttp
RELEASE loUrl
RELEASE loResponse
CANCEL
ENDIF
loJson = CreateObject('Chilkat.JsonObject')
lnParsed = loJson.Load(loResponse.BodyStr)
IF ((lnSuccess <> 1) OR (loResponse.StatusCode < 200) OR (loResponse.StatusCode >= 300)) THEN
? "Lookup failed. HTTP " + STR(loResponse.StatusCode)
IF (lnParsed = 1) THEN
IF (loJson.JsonTypeOf("error.title") = 1) THEN
? loJson.StringOf("error.title")
ENDIF
IF (loJson.JsonTypeOf("error.message") = 1) THEN
? loJson.StringOf("error.message")
ENDIF
ENDIF
RELEASE loHttp
RELEASE loUrl
RELEASE loResponse
RELEASE loJson
CANCEL
ENDIF
IF (lnParsed <> 1) THEN
? "Expected a JSON object in the lookup response."
RELEASE loHttp
RELEASE loUrl
RELEASE loResponse
RELEASE loJson
CANCEL
ENDIF
IF ((loJson.JsonTypeOf("error") = 3)) THEN
? "The service could not complete the lookup."
IF (loJson.JsonTypeOf("error.title") = 1) THEN
? loJson.StringOf("error.title")
ENDIF
IF (loJson.JsonTypeOf("error.message") = 1) THEN
? loJson.StringOf("error.message")
ENDIF
RELEASE loHttp
RELEASE loUrl
RELEASE loResponse
RELEASE loJson
CANCEL
ENDIF
IF ((loJson.JsonTypeOf("bogon") = 5) AND (loJson.BoolOf("bogon") = 1)) THEN
? "This is a reserved or otherwise non-public IP address."
RELEASE loHttp
RELEASE loUrl
RELEASE loResponse
RELEASE loJson
CANCEL
ENDIF
IF ((loJson.JsonTypeOf("ip") <> 1) OR (loJson.StringOfEquals("ip","",1) = 1)) THEN
? "The response did not contain the expected IP address."
RELEASE loHttp
RELEASE loUrl
RELEASE loResponse
RELEASE loJson
CANCEL
ENDIF
? "IP address: " + loJson.StringOf("ip")
IF ((loJson.JsonTypeOf("geo.country") = 1) AND (loJson.StringOfEquals("geo.country","",1) <> 1)) THEN
? "Country: " + loJson.StringOf("geo.country")
ELSE
? "Country: unavailable"
ENDIF
IF ((loJson.JsonTypeOf("geo.country_code") = 1) AND (loJson.StringOfEquals("geo.country_code","",1) <> 1)) THEN
? "Country code: " + loJson.StringOf("geo.country_code")
ELSE
? "Country code: unavailable"
ENDIF
IF ((loJson.JsonTypeOf("geo.region") = 1) AND (loJson.StringOfEquals("geo.region","",1) <> 1)) THEN
? "Region: " + loJson.StringOf("geo.region")
ELSE
? "Region: unavailable"
ENDIF
IF ((loJson.JsonTypeOf("geo.city") = 1) AND (loJson.StringOfEquals("geo.city","",1) <> 1)) THEN
? "City: " + loJson.StringOf("geo.city")
ELSE
? "City: unavailable"
ENDIF
IF ((loJson.JsonTypeOf("geo.timezone") = 1) AND (loJson.StringOfEquals("geo.timezone","",1) <> 1)) THEN
? "Time zone: " + loJson.StringOf("geo.timezone")
ELSE
? "Time zone: unavailable"
ENDIF
* Missing coordinates stay unavailable. A numeric zero is a valid coordinate.
IF ((loJson.JsonTypeOf("geo.latitude") = 2) AND (loJson.JsonTypeOf("geo.longitude") = 2)) THEN
? "Coordinates: " + loJson.StringOf("geo.latitude") + ", " + loJson.StringOf("geo.longitude")
ELSE
? "Coordinates: unavailable"
ENDIF
IF ((loJson.JsonTypeOf("as.asn") = 1) AND (loJson.StringOfEquals("as.asn","",1) <> 1)) THEN
? "ASN: " + loJson.StringOf("as.asn")
ELSE
? "ASN: unavailable"
ENDIF
IF ((loJson.JsonTypeOf("as.name") = 1) AND (loJson.StringOfEquals("as.name","",1) <> 1)) THEN
? "Network organization: " + loJson.StringOf("as.name")
ELSE
? "Network organization: unavailable"
ENDIF
RELEASE loHttp
RELEASE loUrl
RELEASE loResponse
RELEASE loJson