2

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Sonia Sharma
  • 137
  • 1
  • 2
  • 8

1 Answers1

1

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());
}
Joni
  • 108,737
  • 14
  • 143
  • 193
  • This is what I was looking for. It will be really nice of you if you could provide me with the link to this code too. – Sonia Sharma Jul 14 '13 at 14:52
  • For getting the IPs for these NSRecord, Do we need to make another lookup request? Other wise how can we get their IPs from additional section?? – Ankur Rastogi Feb 16 '18 at 20:58