Getting the server hostname programmatically
December 02, 2003

Need to know a server's hostname, not the http server name. Try this:
<cfset inet = CreateObject("java", "java.net.InetAddress")>
<cfset inet = inet.getLocalHost()>
<cfoutput>#inet.getHostName()#</cfoutput>
Trackbacks
Trackback Address: 97/5B57D352FC1C94BA890F30337967ED83
Comments
On 12/02/2003 at 3:06:24 PM EST Steve Nelson wrote:
1
why not just use #cgi.server_name#?
On 12/03/2003 at 2:13:23 AM EST Pete Freitag wrote:
2
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.
On 12/03/2003 at 4:11:44 AM EST Barry Frost wrote:
3
Thanks for the tip Pete. An alternative we used was to read the name from the registry: <cfregistry action="get" branch="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" entry="ComputerName" variable="computerName" type="string" />. Of course this isn't an option if you use *nix...
We use the hostname in our applications to <cfinclude> machine-specific settings. This enables us to maintain the same codebase on our development boxes that we have in our test and production environments.
On 12/03/2003 at 5:45:53 AM EST Jason Blum wrote:
4
Does anyone know of any documentation out there, on Macromedia or elsewhere, of all the Java variables and functions available to you like this? How about "factory services"?
On 12/04/2003 at 12:33:53 AM EST Pete Freitag wrote:
5
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.
On 01/10/2004 at 8:45:15 PM EST dan wrote:
6
"documentation out there on Macromedia Java variables and functions"
its called fusdocs (Coldfusion MX javadocs)
On 01/19/2005 at 1:17:53 AM EST ruel brown wrote:
7
what is the server hostname for tripod/lycos. i need this info to get my website up which is hosted by tripod and the domain name is sold to me by funcity.com
thanks ruel brown
On 03/06/2008 at 8:21:46 AM EST fguigou wrote:
8
This is quite useful, if you are running behind a cluster or load-balancing configuration and would like to log or write (hidden, in the HTML response) the id of the server which responded to the request.
Post a Comment
Recent Entries
- Cache Template in Request Setting Explained
- What Version of Java is ColdFusion Using?
- ColdFusion 9 Performance Brief from Adobe
- Request Filtering in IIS 7 Howto
- J2EE Session Cookies on ColdFusion / JRun
- Hands on ColdFusion Security Training
- ColdFusion 9 Solr Vulnerability - Are you at Risk?
- FCKEditor Year 2010 Bug for Firefox 3.6 with ColdFusion
We use the hostname in our applications to <cfinclude> machine-specific settings. This enables us to maintain the same codebase on our development boxes that we have in our test and production environments.
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.
its called fusdocs (Coldfusion MX javadocs)
thanks ruel brown



add to del.icio.us



