`
bits00
  • 浏览: 73831 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

InetAddress类详解

阅读更多

 

package com.test;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Test
{
    public static void main(String[] args)
    {
        try
        {
            // 此类中没有定义构造器,二是通过静态方法返回此类的对象实例
            InetAddress ia = InetAddress.getLocalHost();

            System.out.println(ia.getHostAddress());//10.85.25.18
            System.out.println(ia.getHostName());//tkf77612
            System.out.println(ia.getAddress());//[B@c17164
            System.out.println(ia.getCanonicalHostName());//tkf77612.china.huawei.com

            
            System.out.println(InetAddress.getByName("www.huawe.com"));//www.huawe.com/58.215.65.91
            System.out.println(InetAddress.getByName(null));//localhost/127.0.0.1

         
            byte[] bs = new byte[]{ 127, 123, 0, 1 };
            InetAddress ia2 = InetAddress.getByAddress("dylan", bs);
            System.out.println(ia2);
        }
        catch (UnknownHostException e)
        {
            e.printStackTrace();
        }
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics