日期:2014-05-20  浏览次数:20878 次

如何用JAVA实现通过IP反查域名
在网上搜的很多都不行
求源码~~

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


------解决方案--------------------
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){}

}

}

------解决方案--------------------
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
------解决方案--------------------
//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);
------解决方案--------------------
楼上这个不行:
208.29.194.106
------解决方案--------------------
探讨

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

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

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

------解决方案--------------------
探讨
package com.hellobbboy.net;

import java.net.*;

/**

* 演示InetAddress类的基本使用

*/

public class InetAddressDemo {

public static void main(String[] args) {

try{

//使用域名创建对象

……