Reverse IP Address Lookup with ColdFusion + Java
January 10, 2007
I needed to do a reverse lookup on some IP addresses in a database today. I found that you can do this pretty easily with java, and just as easily with ColdFusion. Here it is:
<cfset inet_address = CreateObject("java", "java.net.InetAddress")>
<cfset host_name = inet_address.getByName("184.108.40.206").getHostName()>
In java this would simply be:
System.out.println( java.net.InetAddress.getByName("220.127.116.11").getHostName() );
Trackback Address: 618/B2C48C72FA8826EB3A8686F940EC781B
Or you could use:
<cfscript> writeOutput(CreateObject("java", "java.net.InetAddress").getByName("18.104.22.168").getHostName()); </cfscript>
[ ]'s great post =)
OR: <cfoutput>#CreateObject("java", "java.net.InetAddress").getByName("22.214.171.124").getHostName()#</cfoutput>
As well =))
Right on Fernando - I wasn't trying to make it look easier in java, but after reading the post again some might have come away with that. The same shortcuts I used in the java example could be used in ColdFusion as you did, above.
Wow. I had a need for using the InetAddress Java class today as well. I planned on blogging it, but you beat me to it.
Has anyone ever done business with http://www.javacitywarehouse.com They
We also use inet_address.getLocalHost().getCanonicalHostName() for one of our sites in a cluster so if a client has an issue we can have them view source and read out the machine name.
http://www.ipgp.net is a good tool to view information about ip addresses
why not use this accurate ip address locator: http://www.ip-adress.com
(I know I'm replying to a 4 year old comment, the question was asked and I'm sure the page is hit to this day. I know I needed a reminder how to do this and ended up here.)
Using the Java method is quicker. If an ISP has set reverse DNS records, the library gives you the rDNS in a few milliseconds. A lookup will always take longer.
rDNS is good data to have when you're tracking down CSRFs or badly behaving web spiders. Sometimes content writers won't add a rel="nofollow" to a link or form tag to keep spiders out. Or someone forgets to disallow a page. Googlebot & others are good but don't post data to forms.
(Cross site request forgery [CSRF or XSRF] is *still* the #1 security issue on web apps even in 2011. Visit OWASP to get the top 10 security issues affecting web apps.)