i did it.look at the code below:
---------------------------------
import java.net.*;
public class getHostname{
public static void main(String[] args)throws UnknownHostException{
InetAddress address=InetAddress.getLocalHost();
System.out.println(address); //print host IP
String hostname=address.getHostName(); //get host name
System.out.println(hostname); //print host name
}
}
---------------------------------
import java.net.*;
public class getHostname{
public static void main(String[] args)throws UnknownHostException{
InetAddress address=InetAddress.getLocalHost();
System.out.println(address); //print host IP
String hostname=address.getHostName(); //get host name
System.out.println(hostname); //print host name
}
}
public static void main(String[] args) throws Exception {
InetAddress a = InetAddress.getByName(args[0]);
byte[] b = {(byte) 192, (byte) 168, (byte) 128, 01};
InetAddress a = InetAddress.getByAddress(b);
System.out.println(a.getHostName());
System.out.println(a.getHostAddress());
}
}
请把这行代码删去
InetAddress a = InetAddress.getByName(args[0]);
public class getHostname{
public static void main(String[] args)throws UnknownHostException{
InetAddress[] hostname=InetAddress.getAllByName("www.163.com");
for(int i=0;i<hostname.length;++i)
System.out.println(hostname[i]);
}
}