Jay
Jay

Reputation: 45

How to fetch all DNS entries from JAVA application?

As of now, I'm using the below code to get DNS name of the given IPAddress. Instead of fetching it for each IPAddress in the network, I want to fetch all the DNS entries (IPAddress - HostName mapping) from the DNS Server in one go. Is it possible? If so, how to do it?

InetAddress addr = InetAddress.getByName(address);
dnsname = addr.getCanonicalHostName().trim();

Upvotes: 1

Views: 2420

Answers (1)

bortzmeyer
bortzmeyer

Reputation: 35449

From a public DNS server, there is no way to pull out all the data it holds. Enumerating all the IP addresses one by one is the only solution.

If you have a special relationship with the DNS server (for instance, it is managed by your employer), you may request from the DNS administrator a right to transfer the whole zone (the DNS request known as AXFR). They may authorize your IP address or gives you a TSIG key to authentify yourself.

Then, you will have to find a way to do a zone transfer (possibly with TSIG authentication) in Java. Using these keywords, I find some code and documentation. Use a code search engine like Google Code Search or Krugle to find examples of use.

[DNS experts will probably scream "Use zone walking on NSEC" but most DNS zones are not signed with NSEC.]

Upvotes: 2

Related Questions