Sample code for 30+ languages & platforms
Xbase++

api.db-ip.com IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the api.db-ip.com REST API.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL cJsonStr
LOCAL oJson
LOCAL cIpAddress
LOCAL cContinentCode
LOCAL cContinentName
LOCAL cCountryCode
LOCAL cCountryName
LOCAL cStateProv
LOCAL cCity

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

//  Lookup an IPv4 address: 149.250.207.170  (this was a randomly chosen address)
cJsonStr := oHttp:QuickGetStr("http://api.db-ip.com/v2/free/149.250.207.170")
IF (oHttp:LastMethodSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    RETURN
ENDIF

oJson := CreateObject("Chilkat.JsonObject")
oJson:EmitCompact := 0
nSuccess := oJson:Load(cJsonStr)

? oJson:Emit()

//  Sample output:
//  Use this online tool to generate parsing code from sample JSON: 
//  Generate Parsing Code from JSON

//  {
//    "ipAddress": "149.250.207.170",
//    "continentCode": "EU",
//    "continentName": "Europe",
//    "countryCode": "DE",
//    "countryName": "Germany",
//    "stateProv": "Baden-W\u00fcrttemberg",
//    "city": "B\u00f6blingen"
//  }

cIpAddress := oJson:StringOf("ipAddress")
cContinentCode := oJson:StringOf("continentCode")
cContinentName := oJson:StringOf("continentName")
cCountryCode := oJson:StringOf("countryCode")
cCountryName := oJson:StringOf("countryName")
cStateProv := oJson:StringOf("stateProv")
cCity := oJson:StringOf("city")

oHttp:destroy()
oJson:destroy()