15_1.InetAddress

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

public class InetAdressTest {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress address = InetAddress.getByName("www.baidu.com");
        //获取对象的域名和ip地址
        System.out.println(address);//www.baidu.com/61.135.169.125
        //获取对象所含的域名
        System.out.println("HostName:"+address.getHostName());//HostName:www.baidu.com
        //获取对象所含的ip地址
        System.out.println("HostAddress:"+address.getHostAddress());//HostAddress:61.135.169.125
        // 获取本机的域名和ip地址
        System.out.println("InetAddress.getLocalHost() = " + InetAddress.getLocalHost());
    }

}

posted @ 2019-09-18 16:15  fly_bk  阅读(128)  评论(0编辑  收藏  举报