|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Find Coldfusion Server's IP Address
How can I find the IP address of the server?
The IP address of the client can by found by: Code:
#CGI.REMOTE_ADDR# Does there happen to be a coldfusion tag like: Code:
<cfoutput>#serverAddress()#</cfoutput> <!--- Output's 192.168.2.2 ---> |
|
#2
|
|||
|
|||
|
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
||||
|
||||
|
Nice Find!
So you can you basically run anything you an write in java through coldfusion? Hmm... I'm better at java than coldfusion. |
|
#4
|
||||
|
||||
|
Hmm... Intresting.
Apprently the IP address the server is using to connect to itself is not the same IP address that is returned by that function. Do you know of other functions like that for me to test out? |
|
#5
|
|||
|
|||
|
You can poke around on cflib.org, but yes, if you know Java then you can invoke any Java API methods from within CF. So you might check out the related Java methods as well.
|
|
#6
|
|||
|
|||
|
<cfexecute name = "C:\WinNT\System32\ipconfig.exe"
arguments = "/all" variable ="crpa" timeout = "1"> </cfexecute><Cfoutput>#crpa#</Cfoutput> check your path to ipconfig... |
|
#7
|
|||
|
|||
|
or the long way
import java.net.*; public class Url001{ public static void main(String[] args){ try{ System.out.println( "Get and display IP address of URL by name"); InetAddress address = InetAddress.getByName( "forums.devshed.com"); System.out.println(address); System.out.println( "Do reverse lookup on the IP address"); //Extract the IP address from the string to the right // of the /. Then provide the IP address as a string // to the getByName() method. int temp = address.toString().indexOf('/'); address = InetAddress.getByName( address.toString().substring(temp+1)); System.out.println(address); System.out.println( "Get and display current IP address of LocalHost"); address = InetAddress.getLocalHost(); System.out.println(address); System.out.println( "Do reverse lookup on current " + "IP address of LocalHost"); temp = address.toString().indexOf('/'); address = InetAddress.getByName( address.toString().substring(temp+1)); System.out.println(address); System.out.println( "Get and display current name of LocalHost"); System.out.println(address.getHostName()); System.out.println( "Get and display current IP address of LocalHost"); //Get IP address as an array of bytes. byte[] bytes = address.getAddress(); //Convert IP address bytes to unsigned values // and display separated by spaces. for(int cnt = 0; cnt < bytes.length; cnt++){ int uByte = bytes[cnt] < 0 ? bytes[cnt] + 256 : bytes[cnt]; System.out.print(uByte + " "); }//end for loop System.out.println(); }catch(UnknownHostException e){ System.out.println(e); System.out.println("Must be online to run properly."); }//end catch }//end main }//end class Url001 of course you will want to CreateObject() then invoke whatever function you want to use in the .class file |
|
#8
|
||||
|
||||
|
My server has multiple IP addresses, 6 to be exact, so I developed the following script to check IP config to determine if the server was connecting to itself. It might be more appropriate to check for someting like "IP Address:.........#CGI.REMOTE_ADDR#" rather than just "#CGI.REMOTE_ADDR", but i knew I wouldn't have to wory about a DNS or IP address Mask connecting to the server and breaking my code.
Also the second script provided by falcon only returns one of the 6 IP addresses. Code:
<!--- Verify Server is Connecting from Itself ---> <cffunction name="verifyServer"> <!--- Pull IP addresses from Windows IPConfig.exe ---> <cfexecute name = "C:\WINDOWS\system32\ipconfig.exe" arguments = "/all" variable ="IPs" timeout = "1" > </cfexecute> <!--- Check if Connecting Address is an IP of the Server ---> <cfif findNoCase(CGI.REMOTE_ADDR, variables.IPs) EQ 0> <!--- Server is NOT connecting to itself ---> <cfreturn 0> <cfelse> <!--- Server IS connecting to itself ---> <cfreturn 1> </cfif> </cffunction> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Find Coldfusion Server's IP Address |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|