import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class GetByName {
public static void main(String[] args){
String hostAddress="www.google.cn";
//InputStreamReader可以将二进制流转化为字符流,使用最为频繁。
BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
try {
hostAddress=bfr.readLine();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
//InetAddress没有公共构造函数
InetAddress net=InetAddress.getByName(hostAddress);
//获得地址组
InetAddress[] addrs=InetAddress.getAllByName(hostAddress);
System.out.println(net);
//result:[url]www.google.com/64.233.189.104[/url]
for(int i=0;i<addrs.length;i++){
System.out.println(addrs[i]);
}
//result:[url]www.google.com/64.233.189.104[/url]
// [url]www.google.com/64.233.189.147[/url]
// [url]www.google.com/64.233.189.99[/url]
InetAddress inet=InetAddress.getLocalHost();
System.out.println(inet);
//result:fdu-hjh/10.11.13.128
} catch (UnknownHostException e) {
System.out.println("Cann't find host:"+hostAddress);
}
}
}