//代码开始 /* 本代码只是提供测试,不提供完全的实际应用的功能,但是你可以利用下面的思路开发你自己的相应的程序,请注意本文提供的socket通信在internet上查询domain(或者ip)的功能不完全正确,因为本文使用的socket访问方式不是访问的相应的domain数据库,所以不能实现精确的domain(或者ip)的查询,但是一切在internet上能被访问到的domain(或者ip)都可以都可以被查询到相应的ip(或者domain),如果需要你也可以使用本文所提及socket访问相应的domain数据库得到完全正确的domain查询功能!在run下面的程序以前,请确定你已经安装了jdk1.3以及配置了相关的参数。 */ import java.net.*; class search { public static void main(String[] args) { try { InetAddress address=InetAddress.getByName(args[0]); //获得你要查询的ip或者domain System.out.println(address); //输出查询结果 } catch (Exception e) { //错误提示 System.out.println("对不起,你查询的站点或者IP未被程序找到,可能原因如下"); System.out.println("1,该站点尚未注册或者该站点尚未启用"); System.out.println("2.你没有连接到网络"); System.out.println("3.该ip地址可能已被DHCP解析,但是尚未指向相应的站点"); } } } //代码结束 转载至enetJava socket功能的一个小应用
2001/02/02 10:17 作者:大风
2001/02/02 10:17 作者:大风
public class Whoname{
public static void main(String[] args)
throws Exception{
if (args.length !=1) {
System.err.println("fuck! input args first!");
System.exit(1);
}
InetAddress a = InetAddress.getByName(args[0]);
System.out.println(a);
}
}
使用方法:例 java Whoname sun.com