开发者

Making a DNS request using Java and timing the response

Could some one show me how I can make a DNS request to a particular DNS server and get the response as well as the response time?

I intend to use this in an signed applet. Is this allowed in an开发者_如何学运维 applet?


The standard Java API's you can use is:

java.net.InetAddress

Or the more advanced JNDI lookup API:

DNS Service Provider for the Java Naming Directory Interface

Both above Java API's will work in an signed applet if the applet is granted the required policy rights (java.net.SocketPermission for example). But when the applet is used on a web page, the user will first be shown a dialog that asks for permission to run. To measure performance of these API calls, one can of course use a simple call to java.lang.Systen.currentTimeMillis()

I do not recommend using dnsjava.org, it used to be popular, but the project has not been updated since 2004.


Just call one of the InetAddress methods, or else have a look at JNDI with the DNS provider.


You need a Java implementation of DNS, such as dnsjava (see examples.html). It's certainly not possible to use this in an applet, as it violates the networking restrictions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜