Question

How can I find the nameservers of a domain name like google.com using Java?

I m using "dnsjava" library to find out the host details, MX records, bind version and zone transfer. But I m unable to find a way to find the nameserver for a domain using Java.

Was it helpful?

Solution

The name servers of a domain are stored in the NS record. If you are able to get the MX record finding the name servers is no different.

Borrowing the example given in dnsjava documentation for listing the MX records:

Record [] records = new Lookup("gmail.com", Type.NS).run();
for (int i = 0; i < records.length; i++) {
    NSRecord ns = (NSRecord) records[i];
    System.out.println("Nameserver " + ns.getTarget());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top