IP

IP

ip地址:InetAddress

  • 唯一定位一台网络上计算机

  • 127.0.0.1 本机localhost

  • ip地址分类

    • ipv4/ipv6

      • IPV4 127.0.0.1, 4个字节组成。

      • IPV6 八个字节组成

    • 公网(互联网) 私网(局域网)

      • ABCD类地址

      • 192.168.xx.xx专门给组织内部使用

  • 域名:记忆IP问题

package com.shushu.net;

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

//测试IP
public class TestInetAddress {
   public static void main(String[] args) throws UnknownHostException {
       //查询本机地址:127.0.0.1/localhost
       InetAddress inetAddress = InetAddress.getByName("127.0.0.1");
       System.out.println(inetAddress);
       InetAddress inetAddress2 = InetAddress.getByName("localhost");
       System.out.println(inetAddress2);

       //查询网站ip地址
       InetAddress inetAddress1 = InetAddress.getByName("www.baidu.com");
       System.out.println(inetAddress1);

       //常用方法
       System.out.println(inetAddress1.getAddress());
       System.out.println(inetAddress1.getCanonicalHostName());//规范名
       System.out.println(inetAddress1.getHostAddress());//ip
       System.out.println(inetAddress1.getHostName());//域名

  }
}

 

 

 

posted @ 2021-04-29 09:12  术树  阅读(867)  评论(0编辑  收藏  举报