Sample code for 30+ languages & platforms
Lua Requires Chilkat v9.5.0.96+

DNS Query AAAA Records

See more DNS Examples

Shows how to perform a DNS query to retrieve AAAA records.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local dns = chilkat.Dns.new()

local json = chilkat.JsonObject.new()
json.emit_compact = false

local success = dns:query("AAAA", "x.com", json)
if not success then
    print(dns.last_error_text)
    return
end

print(json:emit())

-- Sample response.
-- Parsing code below..

-- {
--   "answer": {
--     "aaaa": [
--       {
--         "name": "x.com",
--         "ttl": 229,
--         "ipv6": "2606:4700:4400::ac40:96f2"
--       },
--       {
--         "name": "x.com",
--         "ttl": 229,
--         "ipv6": "2606:4700:4400::6812:250e"
--       }
--     ]
--   }
-- }

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

local name = ""
local ttl = 0
local ipv6 = ""

local i = 0
local count_i = json:size_of_array("answer.aaaa")
while i < count_i do
    json.i = i
    name = json:string_of("answer.aaaa[i].name")
    ttl = json:int_of("answer.aaaa[i].ttl")
    ipv6 = json:string_of("answer.aaaa[i].ipv6")
    i = i + 1
end