Sample code for 30+ languages & platforms
Xbase++

DNS Query AAAA Records

See more DNS Examples

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

Note: This example requires Chilkat v9.5.0.96 or later.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oDns
LOCAL oJson
LOCAL cName
LOCAL nTtl
LOCAL cIpv6
LOCAL i
LOCAL nCount_i

nSuccess := 0

oDns := CreateObject("Chilkat.Dns")

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

nSuccess := oDns:Query("AAAA", "x.com", oJson)
IF (nSuccess == 0)
    ? oDns:LastErrorText
    oDns:destroy()
    oJson:destroy()
    RETURN
ENDIF

? oJson: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

i := 0
nCount_i := oJson:SizeOfArray("answer.aaaa")
DO WHILE i < nCount_i
    oJson:I := i
    cName := oJson:StringOf("answer.aaaa[i].name")
    nTtl := oJson:IntOf("answer.aaaa[i].ttl")
    cIpv6 := oJson:StringOf("answer.aaaa[i].ipv6")
    i := i + 1
ENDDO

oDns:destroy()
oJson:destroy()