????3??InetAddress???????
publicclassDemo1
{
publicstaticvoidmain(String[]args)
{
InetAddressina;
try
{
ina=InetAddress.getLocalHost();
System.out.println(ina);
System.out.println(ina.getAddress());//?????InetAddress???????IP???
System.out.println(ina.getHostAddress());//????IP??????????????????????????
System.out.println(ina.getHostName());//?????IP???????????
System.out.println(ina.getLocalHost());//???????????
}
catch(UnknownHostExceptione)
{
//TODO????????catch??
e.printStackTrace();
}
InetAddressina1;
try
{
ina1=InetAddress.getByName("192.168.1.119");
System.out.println(ina1);
}
catch(UnknownHostExceptione)
{
//TODO????????catch??
e.printStackTrace();
}
InetAddress[]ina2;
try
{
ina2=InetAddress.getAllByName("www.microsoft.com");
for(inti=0;i<ina2.length;i++)
System.out.println(ina2[i]);
}catch(UnknownHostExceptione)
{
//TODO????????catch??
e.printStackTrace();
}
}
}