Last active
October 24, 2016 15:56
-
-
Save displague/112ebea7979d60ddd2d0228148f22458 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
// converted to cfscript from https://www.petefreitag.com/item/487.cfm | |
array function srv_lookup(required string name, numeric timeout=60, numeric retries=3) { | |
var ht = createobject("java", "java.util.Hashtable"); | |
ht.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); | |
// with arg: string dnsserver="8.8.8.8" | |
// ht.put("java.naming.provider.url", "dns://" & arguments.dnsserver); | |
ht.put("com.sun.jndi.dns.timeout.initial", arguments.timeout); | |
ht.put("com.syb.jndi.dns.timeout.retries", arguments.retries); | |
var dir = createobject("java", "javax.naming.directory.InitialDirContext"); | |
dir.init(ht); | |
var ret = []; | |
var type = ['SRV']; | |
try { | |
var attrs = dir.getAttributes(arguments.name, type); | |
var attr_enum = attrs.getAll(); | |
while(attr_enum.hasMore()) { | |
var attr = attr_enum.next(); | |
var fields = attr.toString().listtoArray(' ', true); | |
ret.append({priority:fields[2], weight:fields[3], port:fields[4], target:fields[5]}); | |
} | |
} catch ("javax.naming.NameNotFoundException" nnfe) { | |
} | |
return ret; | |
} | |
variables.name = "_bar._tcp.example.org"; | |
//variables.name = "_foo._tcp.example.org"; | |
writeDump(srv_lookup(variables.name)); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment