Lua
Lua
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 Lua Downloads
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("http://api.db-ip.com/v2/free/149.250.207.170")
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
-- {
-- "ipAddress": "149.250.207.170",
-- "continentCode": "EU",
-- "continentName": "Europe",
-- "countryCode": "DE",
-- "countryName": "Germany",
-- "stateProv": "Baden-W\u00fcrttemberg",
-- "city": "B\u00f6blingen"
-- }
local ipAddress = json:string_of("ipAddress")
local continentCode = json:string_of("continentCode")
local continentName = json:string_of("continentName")
local countryCode = json:string_of("countryCode")
local countryName = json:string_of("countryName")
local stateProv = json:string_of("stateProv")
local city = json:string_of("city")