I have written following code to get MX record for any Domain, here google.com
public class DNSRec {
public static void main(String... args)
{
try{
Record [] records = new Lookup("http://www.google.com", Type.NS).run();
for (int i = 0; i < records.length; i++) {
NSRecord ns = (NSRecord) records[i];
System.out.println("Nameserver " + ns.getTarget());
}
}catch(Exception e){
System.out.println("Exception: "+e.getMessage());
}
}}
Output: Exception: null
I have used org.xbill.DNS lib.
What is going wrong in above code ?
Should i use this library or there is any other better way to get DNS records?
Small example ;) most welcome :) . . . . Your response will be greatly appreciated
My internet connection is fine.
Two things are wrong here:
Lookup
class constructor. You are doing a Nameserver lookup for a domain not a URL. Hence you should usegoogle.com
instead ofhttp://www.google.com
Give this a go: