在网上搜的很多都不行
求源码~~

解决方案 »

  1.   

    不懂,帮你顶
    帮你找时,看到一本书:孙卫琴《Java网络编程精解》
    http://download.csdn.net/download/zhenai0512/2377075
      

  2.   

    package com.hellobbboy.net;import java.net.*;/** * 演示InetAddress类的基本使用 */public class InetAddressDemo {         public static void main(String[] args) {                   try{                            //使用域名创建对象                            InetAddress inet1 = InetAddress.getByName("www.163.com");                            System.out.println(inet1);                            //使用IP创建对象                            InetAddress inet2 = InetAddress.getByName("127.0.0.1");                            System.out.println(inet2);                            //获得本机地址对象                            InetAddress inet3 = InetAddress.getLocalHost();                            System.out.println(inet3);                            //获得对象中存储的域名                            String host = inet3.getHostName();                            System.out.println("域名:" + host);                            //获得对象中存储的IP                            String ip = inet3.getHostAddress();                            System.out.println("IP:" + ip);                   }catch(Exception e){}         }}
      

  3.   

    www.163.com/183.60.136.64
    /127.0.0.1
    BS-PC-389/192.168.40.95
    域名:BS-PC-389
    IP:192.168.40.95
      

  4.   

    楼上的代码得到的是本机的IP
    我要的是例如输入: 220.181.111.148
    返回            : www.baidu.com
      

  5.   

    //Get an instance of InetAddress for the IP address
    InetAddress inetAddress = InetAddress.getByName("208.29.194.106");//Get the host name
    String ipAddress = inetAddress.getHostName();//Print the host name
    System.out.println(ipAddress);
      

  6.   

    楼上的
    System.out.println(ipAddress); 结果还不是 208.29.194.106
      

  7.   

    有時候是會失敗的,失敗就仍返回ip,這取決於系統配置的搜索服務(system configured name lookup service)能否反向搜索到域名public String getHostName()
    Gets the host name for this IP address. 
    If this InetAddress was created with a host name, this host name will be remembered and returned; otherwise, a reverse name lookup will be performed and the result will be returned based on the system configured name lookup service. If a lookup of the name service is required, call getCanonicalHostName. If there is a security manager, its checkConnect method is first called with the hostname and -1 as its arguments to see if the operation is allowed. If the operation is not allowed, it will return the textual representation of the IP address. 比如這個 74.125.71.99 能搜索到 hx-in-f99.1e100.net,但不是原先的www.google.com
    ip到domain是一對多映射啊
      

  8.   

    系統配置的搜索服務 系统指的是哪个?
    问题就在 一般新浪 百度的网站 都不支持反向解析
    支持的话 很多方法就可以得到域名了
     getHostName 国内的一般网站基本没一个得到域名 
      

  9.   

    域名到ip的解析 本身就经过了很多工序
    像163,sina,google那些,都是有负载均衡机制的,实际的访问地址可能根据对方路由表的变化而变化
    再加上现在各种例如CDN网络之类的
    所以,从理论来说,ip反查域名是没有多少意义的
    一般的反查是用ip来确定主机所在城市而已
      

  10.   

    这里提供了一些可能有用的信息,貌似可以通过java properties来设置name service providerhttp://docs.oracle.com/javase/1.4.2/docs/guide/net/properties.htmlJNDI DNS service provider settings    These properties may not be supported in future releases.    sun.net.spi.nameservice.provider.<n>=<default|dns,sun|...>
            Specifies the name service provider that you can use. By default, Java will use the system configured name lookup mechanism, such as file, nis, etc. You can specify your own by setting this option. takes the value of a positive number, it indicates the precedence order with a small number takes higher precendence over a bigger number. In J2SETM 1.4, we have provided one DNS name service provider through JNDI, which is called "dns,sun".
    现在版本的jdk应该也有一种类似的机制才对
      

  11.   


    www.163.com/182.140.142.87
    /127.0.0.1
    cyg-gxr1314/192.168.1.55
    域名:cyg-gxr1314
    IP:192.168.1.55
    很好很强大啊。。收下了