InetAddress,此类表示Internet协议(IP)地址
Ipv4:32位地址,以点分十进制表示,如192.168.0.1
Ipv6:128位地址(16个字节)写成8个16位的无符号整数,每个整数用四个十六进制位表示,数之间用:分开
InetAddress addr = InetAddress.getLocalHost();
System.out.println(addr.getHostAddress());
System.out.println(addr.getHostName());
根据域名获得具体的IP地址
InetAddress addr = InetAddress.getByName("www.163.com");
System.out.println(addr.getHostAddress());
System.out.println(addr.getHostName());
网友评论