码迷,mamicode.com
首页 > 编程语言 > 详细

dnsjava usage

时间:2019-02-02 17:17:04      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:ext   return   tps   使用方法   name   out   network   success   searching   

linux dig 命令使用方法

https://www.imooc.com/article/26971?block_id=tuijian_wz

 

https://jimwayne.blogspot.com/2012/08/java-dnsjava-dns-query.html

http://dnsjava.org

http://www.dnsjava.org/download/

http://www.xbill.org/dnsjava/dnsjava-current/examples.html

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.");
    }
}

dnsjava usage

标签:ext   return   tps   使用方法   name   out   network   success   searching   

原文地址:https://www.cnblogs.com/bluestorm/p/10348731.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!