IP

作者: YAOPRINCESS | 来源:发表于2020-06-18 15:07 被阅读0次
package com.kang.lesson01;

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

/**
 * @author klr
 * @create 2020-06-18-14:48
 */
//测试IP
public class TestInetAddress {
    public static void main(String[] args) throws UnknownHostException {
        //这个类没有构造器,只能通过静态方法调用

        //查询本机地址
        InetAddress inetAddress1 = InetAddress.getByName("127.0.0.1");
        System.out.println(inetAddress1);
        System.out.println(InetAddress.getByName("localhost"));
        System.out.println(InetAddress.getLocalHost());

        //查询网站地址
        InetAddress inetAddress2 = InetAddress.getByName("www.baidu.com");
        System.out.println(inetAddress2);
        System.out.println(inetAddress2.getAddress());
        System.out.println(inetAddress2.getCanonicalHostName());//规范的名字
        System.out.println(inetAddress2.getHostName());//域名或者自己电脑的名字
        System.out.println(inetAddress2.getHostAddress());
    }
}
/127.0.0.1
localhost/127.0.0.1
DESKTOP-GPM9S8K/192.168.1.59
www.baidu.com/36.152.44.96
[B@6e8cf4c6
36.152.44.96
www.baidu.com
36.152.44.96

相关文章

网友评论

      本文标题:IP

      本文链接:https://www.haomeiwen.com/subject/rgduxktx.html