java服務器端dns解析


import java.net.InetAddress;

public class SimpleDNS {

    public static void main(String[] args) {
        getAllDNS();
        getDNS();
    }

    private static void getAllDNS() {
        try {
            InetAddress[] address = InetAddress.getAllByName("www.google.com");
            for (int i = 0; i < address.length; i++) {
                System.out.println(address[i].getHostAddress());
            }
        } catch (Exception e) {
            System.out.println(e.toString());
            System.exit(1);
        }
    }

    private static void getDNS() {
        try {
            InetAddress address = InetAddress.getByName("mdm.zte.com.cn");
            System.out.println(address.getHostAddress());
        } catch (Exception e) {
            System.out.println(e.toString());
            System.exit(1);
        }
    }

}
getAllDNS獲取域名解析的所有IP地址
getDNS獲取域名解析地址單個
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM