package hundredquestion.internet;
import java.net.InetAddress;
public class GetNetIP
{
public static void main(String[] args)
{
try
{
String site = "www.baidu.com";
InetAddress[] address = InetAddress.getAllByName(site);
System.out.println(address.length);
for(int i = 0; i < address.length;i++)
{
System.out.println(address[i].getHostAddress());
}
}catch(Exception ex)
{
ex.printStackTrace();
}
}
import java.net.InetAddress;
public class GetNetIP
{
public static void main(String[] args)
{
try
{
String site = "www.baidu.com";
InetAddress[] address = InetAddress.getAllByName(site);
System.out.println(address.length);
for(int i = 0; i < address.length;i++)
{
System.out.println(address[i].getHostAddress());
}
}catch(Exception ex)
{
ex.printStackTrace();
}
}
}
//一个站点可能有多个IP地址,因此在获取IP地址时,使用的方法是返回一个对象数组。