Вопрос

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.

Это было полезно?

Решение

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());
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top