用InetAddress.getByName()不就行了嘛,想那么复杂干嘛

解决方案 »

  1.   

    现在就是不能用getByName,只能用getByAddress
      

  2.   

    如下程序运行起来是没有问题:
     public static void main(String[] args){
     byte[] address = new byte[4];
     address[0] = (byte)211;
     address[1] = (byte)68;
     address[2] = (byte)32;
     address[3] = (byte)4;
     try{
     InetAddress school = InetAddress.getByAddress(address);
     System.out.println(school.getHostName());
     }
     catch(UnknownHostException e){
     System.err.println("Shit");
     }
     }
    关于这个byte的问题,大家看看InetAddress的SRC,在代码中能够找到答案
    比如:
    如果那一个byte是负数,则加上256,如果不是则就为本身
    当然JDK中不是这样实现的
      

  3.   

    String sIP = socket.getInetAddress().getHostAddress();
    //this sIP is "d%.d%.d%.d%";