DNS Query with ColdFusion
It has been a while since I've posted one of these java + cfml tricks, so here's a neat one for ya'.
You can use the Java Naming and Directory Interface (JNDI) to perform a DNS query in ColdFusion.
In the example below I use JNDI to look up the MX records (mail exchangers) for gmail.com:
<cfset env = CreateObject("java", "java.util.Hashtable")> <cfset env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory")> <cfset env.put("java.naming.provider.url", "dns://10.0.0.65")> <cfset env.put("com.sun.jndi.dns.timeout.initial", "2000")> <cfset env.put("com.sun.jndi.dns.timeout.retries", "3")> <cfset dirContext = CreateObject("java", "javax.naming.directory.InitialDirContext")> <cfset dirContext.init(env)> <cfset type = ArrayNew(1)> <cfset type = "MX"> <cfset attributes = dirContext.getAttributes("gmail.com", type)> <cfset atribEnum = attributes.getAll()> <cfloop condition="#atribEnum.hasMore()#"> <cfset attribute = atribEnum.next()> <cfoutput>#attribute.toString()#</cfoutput><br /> </cfloop>
You will want to point the
java.naming.provider.url to the IP address of a dns server, in my case I use:
You can also make different types of queries such as
A (address) or
TXT (text records).
I have written a commercial DNS component for ColdFusion as well.
- Getting Size of Heap and Non Heap Memory in CFML - July 17, 2013
- Serializing CFC's in ColdFusion 8 - August 6, 2007
- Reverse IP Address Lookup with ColdFusion + Java - January 10, 2007
- Null Java References in CF 6 vs 7 - January 10, 2006
- CFSummit 2016 Slides - October 17, 2016
- ColdFusion returning empty response with server-error: true
- Careful applying CF11u16, CF2016u8, CF2018u2
- Sessions don't work in Chrome but do in IE
- csrfVerifyToken does not invalidate the token
- The cf_sql_ is optional in cfqueryparam
- Cookie Expires / Max-Age 1969-12-31T23:59:59.000Z
- Burst Throttling on AWS API Gateway Explained
- How to Resolve Java HTTPS Exceptions