Reverse DNS Lookup in ColdFusion

I've began building an internet services utility component for doing things like DNS lookup in ColdFusion. It's basically a wrapper to simplify all the JAVA integration calls.

Although I can technically do the following to do a dns lookup from an ip address natively in ColdFusion:

<cfscript>

inetAddress = createObject("java","java.net.InetAddress")
theHost = inetAddress.getByName("209.200.101.202").getHostName();

</cfscript>

The preceding code can take up to 5 seconds if there's no dns record for the given ip address. In most applications that wait is not exactly acceptable! The InetUtils.cfc uses a java jar file from dnsjava.org that speeds up the lookup even when there's no dns record.

Here's a sample code on how to use it, it also returns all dns records found for the ip address as an array, where the previous code only returns one record:

<cfscript>

inetUtils = createObject("component","InetUtils").init();
dnsRecords = arrayNew(1);

dnsRecords = inetUtils.reverseDNS("209.200.101.202");

for(x = 1; x LTE arrayLen(dnsRecords); x = x + 1){
writeOutput(dnsRecords[x]);
}

</cfscript>

I'll be adding new methods like dns lookup and any other methods that fit this library later on. If you have any ideas or requests, I'd be happy to hear it.

Comments
zip file is invalid...
# Posted By Nathan Miller | 2/21/07 2:39 PM
Hi Nathan,

Thanks for the heads up, I had originally compressed the files using winRaR format and then renamed the extension to .zip. I have fixed the file an re-uploaded it, give it a shot and let me know if you have any problems..

Cheers..
# Posted By phill.nacelli | 2/21/07 2:56 PM
Hi Phill,

thanks for this, excellent.. Quick question, can the reverse lookup return more than one record? I was under the impression it would only ever return one record. Which is why I was suprised to see an array returned.

Whahoo, also having some issues submitting this post, the captcha is pretty complicated...
# Posted By Taco Fleur | 12/3/07 3:48 PM
@Taco Fleur

The return data type is an array for cases where there are multiple dns records pointing to the same ip address being queried.

Cheers,

Phill
# Posted By phill.nacelli | 12/3/07 4:38 PM
Get free your mp3 http://www.mp3bag.net download
# Posted By mp3 | 8/16/08 5:35 AM
# Posted By Play games | 8/16/08 5:47 AM
# Posted By Play games | 8/16/08 5:50 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.003. Powered by ColdFusion Server v8,0,1,195765.