Railo custom tag CFDNS

cfdns usage exampleI was actually surprised it was not in Coldfusion yet: the ability to do dns lookups. Since I'm the official Railo Extension Manager®™, I saw it as an excellent chance to create a new custom tag: CFDNS.
But, as seems to happen with a lot of good ideas, someone else already thought of it. Just check www.cfdns.org :-/

The thing I could still do, was create the code to use it as a custom tag in Railo. I used the existing cfdns code with a few changes, and made a custom tag wrapper for it, and here it is: <CFDNS> for Railo!

Installation

You can install the custom tag by using your Railo server admin.

Go to your Server admin (default is http://localhost/railo-context/admin/server.cfm), click on Extension > Providers, and add the following url:

http://www.railodeveloper.com/ExtensionProvider.cfc

Then, go to Extension > Applications, and install the CFDNS custom tag.

Lastly, you have to restart Railo to be able to use the tag.

Usage

cfdns usage exampleThe tag has 3 main actions:

  • GETADDRESS: Get IP address or CNAME value for hostname
  • GETHOSTNAME: Get hostname for IP address
  • GETDATA: Get DNS data for a given hostname

And 2 helper actions:

  • GETTYPES: returns a list of possible DNS record types to use for attribute "Type"
  • GETCLASSES: returns a list of possible DNS record classes to use for attribute "Class"

Attributes

Name Required Type Default value Description
Action yes String
Must be one of the following: getaddress, gethostname, getdata, gettypes, getclasses
Variable no String cfdns Variable name which will hold the returned value
Output no String query Must be one of the following: query, raw, xml.
When action is gethostname, the returned value is always a string.
Host For action getaddress and getdata: Yes
Otherwise: No
String
Valid hostname
IP For action gethostname:Yes
Otherwise: No
String

IP address
Type no String A The type of DNS record to get. Possible values are: ANY, A, IPSECKEY, LOC, MX, NS, PTR, SIG, SOA, SPF, SSHFP, TXT. This list can be retrieved using <cfdns action="GETTYPES" />
Class no String IN The DNS class to look for. Possible values are: ANY, IN, CH, CHAOS, HS, HESIOD. This list can be retrieved using <cfdns action="GETCLASSES" />
Server no String
The name of a name server to do the DNS lookup at.
Port no Number 53 The port to use when connecting to the nameserver
TCP no Boolean false Use TCP connection to the nameserver, instead of the default UDP
Retries no Number 3 How many retries should be done before giving up on the DNS request
Timeout no Number 5 The timeout in seconds for a DNS lookup

Examples

<h3>Get IP address or CNAME value for hostname<br />
&lt;cfdns action="getaddress" host="mail.google.com" /&gt;<br />
&lt;cfdns action="getaddress" host="googlemail.l.google.com" /&gt;</h3>
<cfdns action="getaddress" host="mail.google.com" />
<cfdump eval=variables.cfdns />
<cfdns action="getaddress" host="googlemail.l.google.com" />
<cfdump eval=variables.cfdns />

<h3>Get hostname for IP address<br />
&lt;cfdns action="gethostname" ip="60.60.60.60" variable="myCFDNSOutput" /&gt;</h3>
<cfdns action="gethostname" ip="60.60.60.60" variable="myCFDNSOutput" />
<pre style="border:1px solid; padding:5px;"><cfoutput>#myCFDNSOutput#</cfoutput></pre>

<h3>Get certain type of DNS records for a hostname<br />
&lt;cfdns action="getdata" host="google.com" type="A" /&gt;</h3>
<cfdns action="getdata" host="google.com" type="A" />
<cfdump eval=cfdns />

<h3>Using the [output] and [timeout] attribute<br />
&lt;cfdns action="getdata" host="microsoft.com" type="A" timeout="30" output="raw" /&gt;</h3>
<cfdns action="getdata" host="microsoft.com" type="A" timeout="30" output="raw" />
<pre style="border:1px solid; padding:5px;"><cfoutput>#cfdns#</cfoutput></pre>

<h3>Get another type of DNS record for a hostname<br />
&lt;cfdns action="getdata" host="google.com" type="MX" /&gt;</h3>
<cfdns action="getdata" host="google.com" type="MX" />
<cfdump eval=cfdns />

<h3>Using "XML" as the output type<br />
&lt;cfdns action="getdata" host="www.getrailo.org" type="A" output="xml" /&gt;</h3>
<cfdns action="getdata" host="www.getrailo.org" type="A" output="xml" />
<pre style="border:1px solid; padding:5px;"><cfoutput>#htmleditformat(cfdns)#</cfoutput></pre>

<h3>Get any type of DNS record for a hostname<br />
&lt;cfdns action="getdata" host="getrailo.org" type="ANY" output="xml" /&gt;</h3>
<cfdns action="getdata" host="getrailo.org" type="ANY" output="xml" />
<pre style="border:1px solid; padding:5px;"><cfoutput>#htmleditformat(cfdns)#</cfoutput></pre>

<h3>Specify a non-default nameserver to do the DNS lookup (and some extra options)<br />
&lt;cfdns action="lookup" host="www.ongevraagdadvies.nl" server="ns1.ongevraagdadvies.com" port="53" tcp="0" retries="3" timeout="5" /&gt;</h3>
<cfdns action="lookup" host="www.ongevraagdadvies.nl" server="ns1.ongevraagdadvies.com" port="53" tcp="0" retries="3" timeout="5" />
<cfdump eval=cfdns />

Thanks!

A big thank you goes out to Joseph Lamoree, who wrote the original cfdns code. The code is freely available from www.cfdns.org.

Questions? Complaints?

Leave a message; I appreciate it! (most of the time ;)

cfdns usage example  cfdns usage example

del.icio.us Digg StumbleUpon Facebook Technorati Fav reddit Google Bookmarks
| Viewed 7418 times
  1. Gert Franz

    #1 by Gert Franz - January 25, 2011 at 11:33 PM

    Paul,

    again great work! Hopefully it wasn't done during the night :-)
    Let's see whether we will include that into the core...

    Gert
  2. Jonathon Lucas

    #2 by Jonathon Lucas - January 26, 2011 at 1:25 PM

    A great addon! I have planned to get this tested on our servers to be released for our Railo hosting customers can use it on their sites :)

    Thumbs up on this!
  3. Paul Klinkenberg

    #3 by Paul Klinkenberg - January 26, 2011 at 3:07 PM

    @Gert and @Jonathan thanks for the compliments :-)
    It wasn't built during the nights; instead, it was built during the days me and my wife were waiting for our baby to be born. At the moment I started to write this blog post, 2 january, suddenly labour began. It only took me another 23 days to finish the blog post ;-)
  4. Tim Meade

    #4 by Tim Meade - December 7, 2012 at 1:33 AM

    I'm trying to use this for a e.164 cnam lookup. In the perl script I have working it has the DNS type as NAPTR. Not having much luck with your tag matching that. Am I missing something? I would certainly like to get your straight Railo tag working!

    Much thanks
  5. Paul Klinkenberg

    #5 by Paul Klinkenberg - December 7, 2012 at 9:27 PM

    Hi Tim, I guess you should start by looking at the underlying code, which I took from www.cfdns.org.
    I hope that helps you out :) Paul
  6. Tim Meade

    #6 by Tim Meade - December 7, 2012 at 11:58 PM

    I modified the main code and just added a new type NAPTR. Using it with RAW output returns the proper raw results. Easy to just parse if for the needed data. Total time with the railo restart about 5 minutes. Thanks for the great head start!
(will not be published)
Leave this field empty

transitive