站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Java 专题使用JNDI进行DNS,邮件服务器,主机信息查找

使用JNDI进行DNS,邮件服务器,主机信息查找

摘要: 使用JNDI进行DNS,邮件服务器,主机信息查找

</td> </tr> <tr> <td width="485" height="35" valign="top" class="ArticleTeitle"> 使用 JNDI 进行DNS, 邮件服务器, 主机信息查找

程序如下:

import java.util.Hashtable;
import java.util.Enumeration;

import javax.naming.*;
import javax.naming.directory.*;

public class JNDISearchDNS {

public static void main(String args[]) {
try {
//Hashtable for environmental information
Hashtable env = new Hashtable();

//Specify which class to use for our JNDI provider
env.put("java.naming.factory.initial","com.sun.jndi.dns.DnsContextFactory");
env.put("java.naming.provider.url", "dns://129.120.210.252/");

String dns_attributes[] = {"MX","A","HINFO"};

//Get a reference to a directory context
DirContext ctx = new InitialDirContext(env);
Attributes attrs1 = ctx.getAttributes("www.163.com",dns_attributes);

if (attrs1 == null) {
System.out.println("host has none of the specified attributes ");
} else {
for (int z = 0; z < dns_attributes.length; z++) {
Attribute attr = attrs1.get(dns_attributes[z]);

if (attr != null) {
System.out.print(dns_attributes[z]+": ");
for (Enumeration vals = attr.getAll();vals.hasMoreElements();) {
System.out.println(vals.nextElement());
}
}

System.out.println(" ");
}
}
} catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}


改程序转自书籍<>.

运行结果:

C:\java>java JNDISearchDNS

A: 202.108.36.196
202.106.168.103
202.106.168.104
202.106.168.109
202.106.168.121
202.108.36.153
202.108.36.155
202.108.36.156
202.108.36.167
202.108.36.172



C:\java></td> <td width="199" valign="top" class="ArticleTeitle">
</td> </tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle">


↑返回目录
前一篇: 一个字符串工具类
后一篇: 将每一个Tab符换成四个空格