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