网络层级

import java.net.InetAddress;
import java.net.UnknownHostException;//测试IP
public class Demo {public static void main(String[] args) throws UnknownHostException {//查询本机地址InetAddress inetAddress = InetAddress.getByName("127.0.0.1");System.out.println(inetAddress);//查询网站ip地址InetAddress inetAddress2 = InetAddress.getByName("www.baidu.com");System.out.println(inetAddress2);//常用方法System.out.println(inetAddress2.getHostAddress());//IPSystem.out.println(inetAddress2.getHostName());//域名}
}