package test; import java.io.IOException; import java.net.InetAddress; public class Test { public static void main(String[] args) throws IOException { String url="www.baidu.com";//不知为什么加上http://报错 InetAddress address=InetAddress.getByName(url); System.out.println("baidu的IP地址:" + address.getHostAddress()) ; } /** *baidu的IP地址:119.75.217.109 */ }