当前位置: 首页 > 工具软件 > dnsjava > 使用案例 >

usage java,dnsjava usage

双弘益
2023-12-01

linux dig 命令使用方法

import java.net.InetAddress;

import java.net.UnknownHostException;

import org.xbill.DNS.*;

public class NetWork {

public static void main(String[] args) throws UnknownHostException, TextParseException {

InetAddress address = InetAddress.getByName("baidu.com");

System.out.println(address.getHostAddress());

//查询域名对应的IP地址

Lookup lookup = new Lookup("baidu.com", Type.A);

// Print the DNS server used by dnsjava

String[] resolvers = ResolverConfig.getCurrentConfig().servers();

for (int i = 0; i < resolvers.length; i++) {

System.out.println("Reslover's default: " + resolvers[i]);

}

// Send DNS query

lookup.run();

if (lookup.getResult() != Lookup.SUCCESSFUL) {

System.out.println("ERROR: " + lookup.getErrorString());

return;

}

Record[] answers = lookup.getAnswers();

for(Record rec : answers){

System.out.println(rec.toString());

}

System.out.println("Searching complete.");

}

}

https://www.cnblogs.com/bluestorm/category/344571.html

 类似资料:

相关阅读

相关文章

相关问答