IP地址

IP地址

  • ip地址:inteAddress

    • 唯一定位的主机

    • 127.0.0.1 本机localhost

    • ip地址的分类

      • ipv4 / ipv6

        • ipv4 127.0.0.1,四个字节 ,0-255,42亿 ;30亿再北美,4亿再亚洲 ,2011年用尽
        • ipv6 16位*8无符号整数 = 128b
      • 公网(互联网)-私网(局域网)

        • ABCD类地址
        • 192.168.xx.xx专门给组织内部使用的
    • 域名:记忆IP

      • IP: 很多IP已经没有了,要买的话很贵

public static void main(String[] args) {
    try {
        //查询网站ip地址
        InetAddress inetAddress = InetAddress.getByName("www.baidu.com");
        System.out.println(inetAddress);

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

        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost);

        //常用方法
        System.out.println(inetAddress.getAddress());
        System.out.println(inetAddress.getCanonicalHostName());
        System.out.println(inetAddress.getHostAddress());
        System.out.println(inetAddress.getHostName());
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
}
posted @ 2021-04-16 13:48  saxon宋  阅读(93)  评论(0)    收藏  举报