dns查询1:DomainNameResolve.java
作者:互联网
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; } }
标签:java,Record,domainName,查询,records,Lookup,dns,lookup,DomainNameResolve 来源: https://blog.51cto.com/11732619/2676994