Created
August 20, 2022 00:35
-
-
Save trycf/78813381cfd93216f805fa62aaf41e74 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
function dnsLookup(domain, type, dnsServer = "8.8.8.8", timeout = 2000, retries = 1){ | |
var dnsRecords = []; | |
var env = CreateObject('java','java.util.Hashtable'); | |
env.put('java.naming.factory.initial','com.sun.jndi.dns.DnsContextFactory'); | |
env.put('java.naming.provider.url', 'dns://#dnsServer#'); | |
env.put('com.sun.jndi.dns.timeout.initial', javaCast('string', timeout)); | |
env.put('com.sun.jndi.dns.timeout.retries', javaCast( 'string', retries)); | |
var dirContext = CreateObject('java', 'javax.naming.directory.InitialDirContext'); | |
dirContext.init( env ); | |
try { | |
var records = dirContext.getAttributes( domain, [ type ] ).get( type ).getAll(); | |
while( records.hasMore() ) { | |
var record = records.next().ToString(); | |
dnsRecords.append( record ); | |
} | |
} catch ( any e ){} //if there are no records, the lookup fails | |
return dnsRecords; | |
} | |
mxRecords = dnsLookup( "mattclemente.com", "MX" ); | |
writeDump( mxRecords ); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment