使用InetAddress类的方法获取http://www.hunnu.edu.cn/的主机的IP地址;获取本地机的名称和IP地址。
大佬帮忙看看哪里有问题!!!程序代码:
import *; public class InetAdressTest { public static void main(String[] args){ InetAddress address; try { address = InetAddress.getByName("http://www.hunnu.); String Hostaddr1 = address.getHostAddress(); System.out.println("主机IP:" + Hostaddr1); address = InetAddress.getLocalHost(); String HostName = address.getHostName(); String Hostaddr2 = address.getHostAddress(); System.out.println("本地主机名:" + HostName); System.out.println("本地主机IP:" + Hostaddr2); } catch (UnknownHostException e) { e.printStackTrace(); } } }