Developing using DNS4J

Query DNS server. Example:

import java.net.InetAddress;
import it.lorenzoingrilli.dns4j.protocol.Clazz;
import it.lorenzoingrilli.dns4j.protocol.Message;
import it.lorenzoingrilli.dns4j.protocol.Type;
import it.lorenzoingrilli.dns4j.protocol.impl.MessageBuilder;
import it.lorenzoingrilli.dns4j.resolver.impl.DNSClient;

public class Test {
    public static void main(String[] args) throws Exception {
        DNSClient client = new DNSClient();
        client.addServer(InetAddress.getByName("8.8.8.8"), 53);
        MessageBuilder mb = new MessageBuilder();  
        Message req =
            mb          
            .question()
            .recursionDesidered(true)
            .addQuestion("www.gentoo.org", Type.A)
            .message();
       
        Message resp = client.query(req);
        System.out.println("REQUEST  "+req);
        System.out.println("RESPONSE "+resp);           
    }    
}

 

This is the output:

REQUEST  Message(header=Header(id=10531, qr=false, opcode=0, aa=false, tc=false, rd=true, ra=false, z=0, rcode=0, qd=1, an=0, ns=0, ar=0), question=[Question(name=www.gentoo.org, type=1, class=1)], answer=[], authority[], additional=[])
RESPONSE Message(header=Header(id=10531, qr=true, opcode=0, aa=false, tc=false, rd=true, ra=true, z=0, rcode=0, qd=1, an=2, ns=0, ar=0), question=[Question(name=www.gentoo.org, type=1, class=1)], answer=[CNAME(name=www.gentoo.org, ttl=507, cname=www-bytemark.gentoo.org), A(name=www-bytemark.gentoo.org, ttl=507, address=89.16.167.134)], authority[], additional=[])