1.3 IP
IP地址:InetAdress
唯一定位网络上的计算机
127.0.0.1:本机localhost
IP地址的分类;
1.IP的分类:公网(互联网)和私网(局域网)
ABCD类地址:0~255折半折半折半
192.168.xx.xx专门给组织内部使用的
域名:记忆IP问题
IP:好点的域名很贵:www.vip.com唯品会的域名 越短的越贵
2.IPV4
127.0.0.1 ,4个字节组成。每个字节0~255 42亿;三十亿都在北美
3.IPV6
未来都会编程IPv6
128位 8个无符号整数
2001:0bb2:aaaa:0015:0000:1aaa:1312
import java.net.InetAddress;
import java.net.UnknownHostException;
public class TestInetAddress {
public static void main(String[] args) {
try {
InetAddress[] addresses1 = InetAddress.getAllByName("127.0.0.0");
System.out.println(addresses1);
InetAddress[] addresses3 = InetAddress.getAllByName("localhost");
System.out.println(addresses3);
InetAddress inetAddress4= InetAddress.getLocalHost();
System.out.println(inetAddress4);
InetAddress addresses2 = InetAddress.getByName("www.baidu.com");
System.out.println(addresses2);
System.out.println(addresses2.getAddress());
System.out.println(addresses2.getCanonicalHostName());
System.out.println(addresses2.getHostAddress());
System.out.println(addresses2.getHostName());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-2853.html