Reverse IP Address Lookup with ColdFusion + Java

by Pete Freitag

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("66.249.66.99").getHostName()>
<cfoutput>#host_name#</cfoutput>

In java this would simply be:

System.out.println( java.net.InetAddress.getByName("66.249.66.99").getHostName() );

The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.

Comments

Fernando S. Trevisan

Or you could use: <cfscript> writeOutput(CreateObject("java", "java.net.InetAddress").getByName("66.249.66.99").getHostName()); </cfscript> [ ]'s great post =)

Fernando S. Trevisan

OR: <cfoutput>#CreateObject("java", "java.net.InetAddress").getByName("66.249.66.99").getHostName()#</cfoutput> As well =))

Pete Freitag

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.

Scott F Stroz

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.

Adam Howitt

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.