如何用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
[解决办法]