tags:

views:

253

answers:

2

Hi everyone,

If I look up a IP address from a DNS name as follows:

InetAddress inetAddress = InetAddress.getByName(name);
String address = inetAddress.getHostAddress();

Can I find out which nameserver gave me the information?

+2  A: 

I'm not sure if this is what you want, but there's a DNSJava library which provides DNS functionality in Java. Perhaps you can use this to either get a better understanding of your issues, or to implement a particular solution ? Like I say, not a perfect match for you, but perhaps helpful.

Brian Agnew
+1  A: 

For a given InetAddress, try the following:

// get the default initial Directory Context
InitialDirContext idc = new InitialDirContext();
// get the DNS records for inetAddress
Attributes attributes = idc.getAttributes("dns:/" + inetAddress.getHostName());
// get an enumeration of the attributes and print them out
NamingEnumeration attributeEnumeration = attributes.getAll();
System.out.println("-- DNS INFORMATION --");
while (attributeEnumeration.hasMore()) {
    System.out.println("" + attributeEnumeration.next());
}
attributeEnumeration.close();

Adapt it to pick up what you're looking for.

Pascal Thivent
Didn't work for me. I just got the A records, no other attributes. Maybe an environmental thing.
Brabster
Well, *An A record gives you the IP address of a domain*. Isn't this precisely what you asked for?
Pascal Thivent