package dns;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
public class DomainNameResolve {
public Record[] domainNameResolve(String domainName, int mxType) {
Record records[] = null;
try {
/* MX = 15;
* A = 1;
* PTR = 12;
* TXT = 16;
*/
Lookup lookup = new Lookup(domainName, mxType); //Type.MX是int类型 可换成数字
lookup.run();
/* lookup.SUCCESSFUL 返回0
* lookup.getResult() 如果查询到返回0, 没查询到返回3
*/
if(lookup.getResult() == Lookup.SUCCESSFUL) {
records = lookup.getAnswers(); // 结果是一个数组
}else {
System.out.println(domainName + " 未查到结果!");
}
} catch (Exception e) {
e.printStackTrace();
}
return records;
}
}