I 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
- 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 />
<cfdns action="getaddress" host="mail.google.com" /><br />
<cfdns action="getaddress" host="googlemail.l.google.com" /></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 />
<cfdns action="gethostname" ip="60.60.60.60" variable="myCFDNSOutput" /></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 />
<cfdns action="getdata" host="google.com" type="A" /></h3>
<cfdns action="getdata" host="google.com" type="A" />
<cfdump eval=cfdns />
<h3>Using the [output] and [timeout] attribute<br />
<cfdns action="getdata" host="microsoft.com" type="A" timeout="30" output="raw" /></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 />
<cfdns action="getdata" host="google.com" type="MX" /></h3>
<cfdns action="getdata" host="google.com" type="MX" />
<cfdump eval=cfdns />
<h3>Using "XML" as the output type<br />
<cfdns action="getdata" host="www.getrailo.org" type="A" output="xml" /></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 />
<cfdns action="getdata" host="getrailo.org" type="ANY" output="xml" /></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 />
<cfdns action="lookup" host="www.ongevraagdadvies.nl" server="ns1.ongevraagdadvies.com" port="53" tcp="0" retries="3" timeout="5" /></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 ;)
#1 by Gert Franz - January 25, 2011 at 11:33 PM
again great work! Hopefully it wasn't done during the night :-)
Let's see whether we will include that into the core...
Gert
#2 by Jonathon Lucas - January 26, 2011 at 1:25 PM
Thumbs up on this!
#3 by Paul Klinkenberg - January 26, 2011 at 3:07 PM
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 by Tim Meade - December 7, 2012 at 1:33 AM
Much thanks
#5 by Paul Klinkenberg - December 7, 2012 at 9:27 PM
I hope that helps you out :) Paul
#6 by Tim Meade - December 7, 2012 at 11:58 PM