Reverse IP Address Lookup with ColdFusion + Java
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("22.214.171.124").getHostName()> <cfoutput>#host_name#</cfoutput>
In java this would simply be:
System.out.println( java.net.InetAddress.getByName("126.96.36.199").getHostName() );
Like this? Follow me ↯Tweet Follow @pfreitag
You might also like:
- DNS Query with ColdFusion - October 27, 2005
- Getting Size of Heap and Non Heap Memory in CFML - July 17, 2013
- CFML on Google App Engine for Java - April 10, 2009
- Serializing CFC's in ColdFusion 8 - August 6, 2007
- Null Java References in CF 6 vs 7 - January 10, 2006
- Thread Priority, and Yielding - April 6, 2005
- Bookmarklets and Search Plugins for javadocs.org - May 12, 2004
- Checking your JDBC Driver Version - March 31, 2004
Or you could use: <cfscript> writeOutput(CreateObject("java", "java.net.InetAddress").getByName("188.8.131.52").getHostName()); </cfscript> [ ]'s great post =)
OR: <cfoutput>#CreateObject("java", "java.net.InetAddress").getByName("184.108.40.206").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.
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