Coldfusion: DNS Reverse Lookup
I have no idea why this information was so difficult to find, but I'm posting it here in case I ever need it again.
To do a reverse lookup in coldfusion:
<cfscript>
rawIP = createObject("java", "java.net.InetAddress").getByName('#ipaddress#').getAddress();
hostname = createObject("java", "java.net.InetAddress").getByAddress('#rawIP#').getHostName();
chostname = createObject("java", "java.net.InetAddress").getByAddress('#rawIP#').getCanonicalHostName();
</cfscript>
Note — this is slow. If you're doing them in bulk, you may need to go in small batches or set a higher timeout.
Also, this was perhaps useful: http://api.hostip.info/get_html.php?ip=#ipaddress#&position=true — returns the country, city, state, and geotag info for an IP address, where available.
Filed by JC at February 19th, 2009 under ColdFusion
This works great if it wasnt so slow. We're using this to log the host names of our users, and Im looking up anywhere between 6-10k addresses at a time, which doesnt make this usage feasible. What we've noticed though, is that it only takes a while if it is unable to find a host name. Otherwise, its back in less than a second. Do you or anyone know of any way to cancel the request if it takes longer than a specified period of time and just move on to the next one if that's the case?
Comment by Greg — June 10, 2009 @ 1:46 pm