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
}
}

解决方案 »

  1.   

    import java.net.*;public class WhoAmI {
        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());    
        }
    }
      

  2.   

    在byte[] 数组中,元素的值大于127时就用(byte) 强制转换一下
      

  3.   

    sorry
    请把这行代码删去
    InetAddress a = InetAddress.getByName(args[0]);
      

  4.   

    import java.net.*;
    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]);
    }
    }