Sample code for 30+ languages & platforms
Lua

ipapi.co IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the ipapi.co REST API.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

-- Lookup an IPv4 address: 149.250.207.170  (this was a randomly chosen address)
local jsonStr = http:quick_get_str("https://ipapi.co/149.250.207.170/json")
if not http.last_method_success then
    print(http.last_error_text)
    return
end

local json = chilkat.JsonObject.new()
json.emit_compact = false
local success = json:load(jsonStr)

print(json:emit())

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

-- {
--   "ip": "149.250.207.170",
--   "city": "B�blingen",
--   "region": "Baden-W�rttemberg",
--   "region_code": null,
--   "country": "DE",
--   "country_name": "Germany",
--   "continent_code": "EU",
--   "in_eu": true,
--   "postal": null,
--   "latitude": null,
--   "longitude": null,
--   "timezone": null,
--   "utc_offset": null,
--   "country_calling_code": "+49",
--   "currency": "EUR",
--   "languages": "de",
--   "asn": "AS15854",
--   "org": "EntServ Deutschland GmbH"
-- }

local ip = json:string_of("ip")
local city = json:string_of("city")
local region = json:string_of("region")
local region_code = json:string_of("region_code")
local country = json:string_of("country")
local country_name = json:string_of("country_name")
local continent_code = json:string_of("continent_code")
local in_eu = json:bool_of("in_eu")
local postal = json:string_of("postal")
local latitude = json:string_of("latitude")
local longitude = json:string_of("longitude")
local timezone = json:string_of("timezone")
local utc_offset = json:string_of("utc_offset")
local country_calling_code = json:string_of("country_calling_code")
local currency = json:string_of("currency")
local languages = json:string_of("languages")
local asn = json:string_of("asn")
local org = json:string_of("org")