Solved

port number of server

Posted on 2002-07-15
19
335 Views
Last Modified: 2013-12-24
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
Comment
Question by:dash420
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +6
19 Comments
 
LVL 3

Expert Comment

by:SewellM
ID: 7154181
#cgi.server_port# comes to mind.  

Michael
0
 
LVL 6

Author Comment

by:dash420
ID: 7154246
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
 
LVL 5

Expert Comment

by:Yog
ID: 7155385
ip address ? #CGI.REMOTE_ADDR#
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 2

Expert Comment

by:tleish
ID: 7155387
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
 
LVL 6

Author Comment

by:dash420
ID: 7156148
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
 
LVL 1

Expert Comment

by:Agatheeswaran
ID: 7192602
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
 
LVL 6

Author Comment

by:dash420
ID: 7192609
where to ping ??
0
 
LVL 5

Expert Comment

by:Yog
ID: 7193590
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
 
LVL 1

Expert Comment

by:parekh_minal
ID: 7213581
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
 
LVL 6

Author Comment

by:dash420
ID: 7213776
It is not port of server where http service comes from i want, I want server ip address.
0
 
LVL 5

Expert Comment

by:CFXPERT
ID: 7218500
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
 
LVL 5

Expert Comment

by:CFXPERT
ID: 7218525
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
 
LVL 6

Author Comment

by:dash420
ID: 7219509
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
 
LVL 5

Expert Comment

by:CFXPERT
ID: 7219908
hmmm.  Are you running WIN2k server?

0
 
LVL 6

Author Comment

by:dash420
ID: 7219922
yaah. you are right. we have winnt
0
 
LVL 5

Expert Comment

by:CFXPERT
ID: 7220026
Does the server have more than one NIC card installed?
0
 
LVL 2

Expert Comment

by:fmedia
ID: 7572348
<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
 

Expert Comment

by:modulo
ID: 8421962
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8446154
Saving this Q as a PAQ and refunding the 50 points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question