Pete Freitag Pete Freitag

Getting the server hostname in CFML

Updated on November 13, 2023
By Pete Freitag
coldfusionjava

Need to know a server's hostname, not the http server name using CFML (ColdFusion). Try this:
<cfset inet = CreateObject("java", "java.net.InetAddress")>
<cfset inet = inet.getLocalHost()>
<cfoutput>#inet.getHostName()#</cfoutput>

Getting the server hostname in CFML was first published on December 02, 2003.

Fixinator

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.


Try Fixinator

CFBreak
The weekly newsletter for the CFML Community


Comments

why not just use #cgi.server_name#?
by Steve Nelson on 12/02/2003 at 3:06:24 PM UTC
That returns different values depending on the web site domain. This method always returns the server's hostname. I'm not sure why you would need that specifically, but someone asked for it, and this is the solution I came up with.
by Pete Freitag on 12/03/2003 at 2:13:23 AM UTC
Hi Jason,

What I'm using here is part of the standard Java API. Documentation for it can be found here: http://java.sun.com/j2se/1.4.1/docs/api/


The service factories in ColdFusion MX are not documented by Macromedia at all, they don't really want you messing with them. When CFMX first came out I posted some undocumentation here: http://www.cfdev.com/mx/undocumentation/ it doesn't cover the service factory, but it does cover some other features.
by Pete Freitag on 12/04/2003 at 12:33:53 AM UTC
"documentation out there on Macromedia Java variables and functions"

its called fusdocs (Coldfusion MX javadocs)
by dan on 01/10/2004 at 8:45:15 PM UTC