InetAddress 테스트

5802 단어 InetAddress
다음은 InetAddress에 대한 몇 가지 테스트입니다.
package com.ddc.gemantic;



import java.net.InetAddress;

import java.net.UnknownHostException;



public class InetAddressTestMain {



    /**  InetAddress   

     *    :   、    、ip  、ipv4、ipv6

     * InetAddress        

     * InetAddress     ,  3   :    、    、  ip

     *   ip         ,           ip(             ),          ip(  web            ),  ip         (  web          )

     *          :     ,       ,DNS                  IP

     * 

     * @param args

     * @throws UnknownHostException 

     */

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

        System.out.println("  InetAddress.getByName(host)  InetAddress.getAllByName(host)    ");

        //InetAddress.getByName(host)    InetAddress.getAllByName(host)         ,     InetAddress.getAllByName(host)

        //InetAddress.getAllByName(host)      :  (  )、   、ip  (ipv4:192.168.1.235     ipv6)

        

        /*        InetAddress ,  :www.google.com

         * 1、          ,  DNS,        ,      

         * 2、            ,               。

         * 3、          ip,      InetAddress  

         */

        InetAddress[] googleAddressList=InetAddress.getAllByName("www.google.com");

        for(InetAddress add:googleAddressList)

            System.out.println("ip   :"+add.getHostAddress()+"   (    ) :"+add.getHostName()+"     :"+add.getCanonicalHostName());

        

        /*

         *         InetAddress ,  hx-in-f147.1e100.net(google        )

         * 1、        :          ,  DNS,        ,      

         * 2、               hx-in-f147.1e100.net

         * 3、        ip  

         */

        InetAddress[] googleReallyHostAddressList=InetAddress.getAllByName("hx-in-f147.1e100.net");

        for(InetAddress add:googleReallyHostAddressList)

            System.out.println("ip   :"+add.getHostAddress()+"   (    ) :"+add.getHostName()+"     :"+add.getCanonicalHostName());

        

      /*

       *   ip      InetAddress

       * 1、            DNS

       * 2、                 :InetAddress canonicalHostName   hostName           ,        get   ,    DNS  

       * 3、     ,     DNS,    ip            

       */

        InetAddress[] ipAddressList=InetAddress.getAllByName("74.125.71.99");

        for(InetAddress add:ipAddressList)

            System.out.println("ip   :"+add.getHostAddress()+"   (    ) :"+add.getHostName()+"     :"+add.getCanonicalHostName());

        

        System.out.println("InetAddress.getByAddress(addr)    ;");

        /**

         *    InetAddress.getAllByName() ,  ip        。

         */

        InetAddress byteAddress=InetAddress.getByAddress(ipAddressList[0].getAddress());

        System.out.println("ip   :"+byteAddress.getHostAddress()+"   (    ) :"+byteAddress.getHostName()+"     :"+byteAddress.getCanonicalHostName());

        /**

         *        ip     InetAddress,               ,ip       。

         *   getCanonicalHostName()        。

         */

        InetAddress allInetAddress=InetAddress.getByAddress("hx-in-f147.1e100.net", ipAddressList[0].getAddress());

        System.out.println("ip   :"+allInetAddress.getHostAddress()+"   (    ) :"+allInetAddress.getHostName()+"     :"+allInetAddress.getCanonicalHostName());

        

    }



}

좋은 웹페이지 즐겨찾기