211.157.102.21 --->www.csdn.net不是一一对应的!

解决方案 »

  1.   


    能进一步解释一下原因吗?谢谢我的程序中用域名得到了这样的IP地址,却对应不上?
    我的程序段如下:
                          .
                          .
                          .
                   InetAddress host;
                   host=InetAddress.getByName(args[0]);
                          .
                          .
                   System.out.println("主机 "+host.getHostName()+"的IP地址为:");
                   bytes=host.getAddress();//于此处得到IP
                   for(int i=0;i<4;i++)
                   fourBytes[i]=bytes[i]&0xff;//是这里处理的有问题吗?
                   System.out.println(fourBytes[0]+"."+
                           fourBytes[1]+"."+fourBytes[2]+"."+fourBytes[3]);
                           .
                           .
                           .
      

  2.   

    我用ping www.csdn.net 结果也是211.157.102.21
    说明正确。
      

  3.   

    应该区分服务和服务器的区别。
    一个服务器可以提供多种服务。
    ping www.csdn.net 结果是211.157.102.21
    ping www.csdn2.net 结果也有可能是211.157.102.21
      

  4.   

    服务是通过端口区别的
    IP则标识服务器主机的全网唯一地址,有域名与之一一对应。通过域名得到IP的程序已实现了,如上面代码。
    我现在想通过IP地址得到域名,却在InetAddress中找不到合适的方法,
    请问该怎么办?
      

  5.   

    InetAddress.getByAddress(addrIpByte[]).getCanonicalHostName();
    试试看?!
      

  6.   


    谢谢你,但是
    我在程序中第39行加了一句
    System.out.println(ipNum+"所对应的主机名为:"+
           InetAddress.getByAddress(addrIpByte[]).getCanonicalHostName());编译给出了如下信息:
    DNSClient2.java:39: '.class' expected
                               InetAddress.getByAddress(addrIpByte[]).getCanonicalHo
    stName());///
                                                                    ^
    DNSClient2.java:39: ')' expected
                               InetAddress.getByAddress(addrIpByte[]).getCanonicalHo
    stName());///         ^
    DNSClient2.java:39: cannot resolve symbol
    symbol  : class addrIpByte
    location: class DNSClient2
                               InetAddress.getByAddress(addrIpByte[]).getCanonicalHo
    stName());///
                                                        ^
    DNSClient2.java:39: unexpected type
    required: value
    found   : class
                               InetAddress.getByAddress(addrIpByte[]).getCanonicalHo
    stName());///
                                                                  ^
    4 errors
      

  7.   

    String strHost = InetAddress.getByAddress("192.169.1.4:80".getBytes()).getCanonicalHostName();
    System.out.println(strHost);结果好像不是你要的!
      

  8.   

    好像差不多了。
    再请问
    getByAddress方法的参数是什么类型?返回什么类型?
      

  9.   

    static InetAddress getByAddress(byte[] addr) 
      

  10.   

    谢谢各位
    谢谢lotofu(骆驼)