importjava.net.InetAddress;

importjava.net.UnknownHostException;

publicclassTestInetAddress{

InetAddressmyIpAddress=null;

InetAddress[]myServer=null;

publicstaticvoidmain(Stringargs[]){

TestInetAddressaddress=newTestInetAddress();

System.out.println("YourhostIPis:"+address.getLocalhostIP());

Stringdomain="www.edenw.com";

System.out.println("Theserverdomainnameis:"+domain);

InetAddress[]array=address.getServerIP(domain);

intcount=0;

for(inti=1;i<array.length;i++){

System.out.println("ip"+i+""+address.getServerIP(domain)[i-1]);

count++;

}

System.out.println("IPaddresstotal:"+count);

}

/**

*获得localhost的IP地址

*@return

*/

publicInetAddressgetLocalhostIP(){

try{

myIpAddress=InetAddress.getLocalHost();

}catch(UnknownHostExceptione){

e.printStackTrace();

}

return(myIpAddress);

}

/**

*获得某域名的IP地址

*@paramdomain域名

*@return

*/

publicInetAddress[]getServerIP(Stringdomain){

try{

myServer=InetAddress.getAllByName(domain);

}catch(UnknownHostExceptione){

e.printStackTrace();

}

return(myServer);

}

}