ip地址
ip地址:inetaddress
唯一定位一台网络上计算机
127.0.0.1:本机localhost
C:\Users\admin>ping 127.0.0.1
正在 Ping 127.0.0.1 具有 32 字节的数据:
来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
127.0.0.1 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
ip地址的分类
ipv4、ipv6
ipv4 127.0.0.1,4个字节组成,0~255,42亿;30亿都在北美,亚洲4亿,2011年就用尽;
公网(互联网)-私网(局域网)
ABCD类地址
192.168.xx.xx专门给组织内部使用的
域名:记忆ip问题!
package com.wuming.lesson01;import java.net.InetAddress; import java.net.UnknownHostException;//测试IP public class TestInetAddress {public static void main(String[] args) {try {//查询本机地址InetAddress inetAddress1 = InetAddress.getByName("127.0.0.1");System.out.println(inetAddress1);InetAddress inetAddress2 = InetAddress.getByName("www.baidu.com");System.out.println(inetAddress2);InetAddress inetAddress4 = InetAddress.getLocalHost();System.out.println(inetAddress4);InetAddress inetAddress5 = InetAddress.getByName("localhost");System.out.println(inetAddress5);//常用方法System.out.println(inetAddress2.getAddress());System.out.println(inetAddress2.getCanonicalHostName());//规范的名字System.out.println(inetAddress2.getHostAddress());//ipSystem.out.println(inetAddress2.getHostName());//域名,或者自己电脑的} catch (UnknownHostException e) {e.printStackTrace();}} }
/127.0.0.1
www.baidu.com/163.177.151.109
wanggang/192.168.128.1
localhost/127.0.0.1
[B@1540e19d
163.177.151.109
163.177.151.109
www.baidu.com