[Java] 纯文本查看 复制代码
package com.itheima;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class test01 {
public static void main(String[] args) throws UnknownHostException {
InetAddress address = InetAddress.getByName("XiaoYi");
String name = address.getHostName();
String ip = address.getHostAddress();
System.out.println("主机名:"+name);
System.out.println("IP地址:"+ip);
}
}