Solved

port number of server

Posted on 2002-07-15
19
330 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
  • 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now