Making a DNS request using Java and timing the response

Mridang Agarwalla picture Mridang Agarwalla · Nov 1, 2010 · Viewed 8.7k times · Source

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?

Answer

Kdeveloper picture Kdeveloper · Nov 1, 2010

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.