• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

port number of server

How to get port number of server in which coldfusion is running.
Is there any cgi variable for that, like #cgi.remote_host#
which gives client port number.
0
dash420
Asked:
dash420
  • 6
  • 4
  • 2
  • +6
1 Solution
 
SewellMCommented:
#cgi.server_port# comes to mind.  

Michael
0
 
dash420Author Commented:
This will not gives the port number it will just gives the port in which the webserver handle the http request like

port :80

I want some thing like

172.16.1.161
0
 
YogCommented:
ip address ? #CGI.REMOTE_ADDR#
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
tleishCommented:
I believe you are refering to the server IP ADDRESS, not the server PORT.  The only way I can think of being able to get this is a little workaround.

You can display the IP Address of a machine that is browsing the site (cgi.remote_addr), so if you use <cfhttp> to browse the current page, then the output CGI variable cgi.remote_addr you will be able to get the machine's IP address.

Note: be careful when setting this all up in one page, if done incorrectly it would set up for an infinite loop and could slow down the CF server.  To avoid this, you could split the if/else script below into to different script.

The following script has been tested and does not cause an infinite loop

=== START CODE EXAMPLE ===
<cfset serverIP = "na">
<cfif IsDefined("URL.remote_addr")>
     <cfsetting showdebugoutput="No">
     <cfoutput>
          #cgi.remote_addr#
     </cfoutput>
     <cfabort>
<cfelse>
     <cfhttp url="http://#cgi.http_host##cgi.script_name#?remote_addr=1" timeout="10"/>
     <cfset serverIP = cfhttp.filecontent>
</cfif>

<cfoutput>
     #variables.serverIP#
</cfoutput>
=== END CODE EXAMPLE ===
0
 
dash420Author Commented:
both #CGI.REMOTE_ADDR#  and #cgi.remote_host# will gives the client ip rather than server ip. I tried with tleish code it is givng me access denied. I want ip of server.
0
 
AgatheeswaranCommented:
I think there is no separate server variables for getting Server Ip. Anyhow the Server Ip will be static, use the "ping" command and use the Ip in your code.

thanks
aga
0
 
dash420Author Commented:
where to ping ??
0
 
YogCommented:
I know you need the server port number, you can get the answer by reading the IIS admin documentation. there should be a component which can get this. Didn't have time to look into it. lemme try if i get free.

cheers.
0
 
parekh_minalCommented:
to get the IP address of the client (eg.203.197.203.197)
use the following code in Coldfusion:

<cfoutput>#REMOTE_ADDR#</cfoutput>


to get the host number of the client (eg.80)
use the following code in Coldfusion:

<cfoutput>#SERVER_PORT#</cfoutput>
0
 
dash420Author Commented:
It is not port of server where http service comes from i want, I want server ip address.
0
 
CFXPERTCommented:
Hey there if your server is leasing it's IP you can use this code to grab the IPaddress out of the registry.

If your on a static IP then I can give you another example but not sure if it will work or not.

<CFSET MYIP = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services">
<cfoutput>
<cfregistry action="getall" branch="#MYIP#" TYPE="ANY" NAME="REGQUERY" SORT="VALUE DESC, ENTRY ASC">
</cfoutput>
<cfoutput query="regquery">
<cfif findNoCase("{",entry)  GT 0>
<cfset netAdapter = entry>
</cfif>
</cfoutput>
<cfoutput>
<CFSET MYIP = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\" & netAdapter & "\Parameters\Tcpip\">
</cfoutput>
<cfregistry action="getall" branch="#MYIP#" TYPE="STRING" NAME="myIp" SORT="VALUE DESC, ENTRY ASC">
<cfoutput query="myip">
<cfif entry EQ "dhcpipaddress">
#value#
</cfif>
</cfoutput>

:)

KWK
0
 
CFXPERTCommented:
If you have a static IP on the server then try this code.

You may get a value back of UNSUPPORTED or 0.  This will be because CF cannot recognize the type REG_MULTI_SZ.  I know it doesn't on CF 4.0 but not sure about 4.5 or up.

<CFSET MYIP = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services">
<cfoutput>
<cfregistry action="getall" branch="#MYIP#" TYPE="ANY" NAME="REGQUERY" SORT="VALUE DESC, ENTRY ASC">
</cfoutput>
<cfoutput query="regquery">
<cfif findNoCase("{",entry)  GT 0>
<cfset netAdapter = entry>
</cfif>
</cfoutput>
<cfoutput>
<CFSET MYIP = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\" & netAdapter & "\Parameters\Tcpip\">
</cfoutput>
<cfregistry action="getall" branch="#MYIP#" TYPE="STRING" NAME="myIp" SORT="VALUE DESC, ENTRY ASC">
<cfoutput query="myip">
<cfif entry EQ "ipaddress">
#value#
</cfif>
</cfoutput>

cheers

KWK
0
 
dash420Author Commented:
thanks cfexperts. i just cut and paste ur both code it fails in both. atleast first one gives some 0.0.0.0
but for second one nothing comes out.
0
 
CFXPERTCommented:
hmmm.  Are you running WIN2k server?

0
 
dash420Author Commented:
yaah. you are right. we have winnt
0
 
CFXPERTCommented:
Does the server have more than one NIC card installed?
0
 
fmediaCommented:
<cfobject type="java" name="objDNS" class="java.net.InetAddress" action="create">
<cfscript>
addr = objDNS.getByName(cgi.SERVER_NAME);
raddr = addr.getHostAddress();
</cfscript>
<cfoutput>
#raddr#
</cfoutput>

i think this should do it
0
 
moduloCommented:
Dear expert(s),

A request has been made to close this Q in CS:
http://www3.experts-exchange.com/Community_Support/Q_20599426.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 
moduloCommented:
Saving this Q as a PAQ and refunding the 50 points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 2
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now