Lua
Lua
ip-api.com IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the ip-api.com 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://ip-api.com/json/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
-- {
-- "as": "AS15854 Hewlett Packard GmbH",
-- "city": "B�blingen",
-- "country": "Germany",
-- "countryCode": "DE",
-- "isp": "Triaton Frankfurt",
-- "lat": 48.6779,
-- "lon": 8.97297,
-- "org": "EntServ Deutschland GmbH",
-- "query": "149.250.207.170",
-- "region": "BW",
-- "regionName": "Baden-W�rttemberg",
-- "status": "success",
-- "timezone": "Europe/Berlin",
-- "zip": "71034"
-- }
local as = json:string_of("as")
local city = json:string_of("city")
local country = json:string_of("country")
local countryCode = json:string_of("countryCode")
local isp = json:string_of("isp")
local lat = json:string_of("lat")
local lon = json:string_of("lon")
local org = json:string_of("org")
local query = json:string_of("query")
local region = json:string_of("region")
local regionName = json:string_of("regionName")
local status = json:string_of("status")
local timezone = json:string_of("timezone")
local zip = json:string_of("zip")