KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: A utility to acquire the external IP address of a machine
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: May 30, 2013

There are times when it is helpful to have someone test your web site that is not at your location. The challenge is to get to correct URL for the machine running 4D Web Server. The 4D Internet Commands plugin command IT_MyTCPAddr will return the LAN TCP/IP address of the machine, but it will not return the external IP address. The utility below, UTIL_Get_External_IP, will return the external IP address of the machine hosting 4D Web Server

This is an advanced level Tech Tip and a discussion of the installation and use of cURL follows the method.

If (False)
   Begin SQL
      /*
       Name: UTIL_Get_External_IP
       Path: UTIL_Get_External_IP

       Purpose: Get the external IP address for a machine using cURL
         cURL is a command line tool for transferring data with URL syntax.
         See <http://curl.haxx.se>

       $0 - TEXT - The external IP of a computer
      */
   End SQL
End if
C_TEXT($MethodName_T)
$MethodName_T:=Current method name
//===================== Declare Variables ==================================
//method_parameters_declarations
C_TEXT($0;$Addr_T)
//--------------------------------------------------------------------------------
//method_wide_constants_declarations
//--------------------------------------------------------------------------------
//local_variable_declarations
C_LONGINT($Ndx;$SOA;$RIS;$Params_L)
C_LONGINT($Platform_L;$System_L)
C_TEXT($Str_T)
End if
//====================== Initialize and Setup ================================

$Params_L:=Count parameters

//======================== Method Actions ==================================

$Str_T:="curl icanhazip.com"

PLATFORM PROPERTIES($Platform_L;$System_L)
If ($Platform_L=Windows)
   SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true")
End if

LAUNCH EXTERNAL PROCESS($Str_T;$Addr_T;$Addr_T)
$Addr_T:=Substring($Addr_T;1;Length($Addr_T)-1)

//======================== Clean up and Exit =================================

$0:=$Addr_T


cURL is a command-line tool available from the cURL website at http://curl.haxx.se/.

cURL comes already installed in the bash shell on Mac OSX. It does not come automatically insalled on all versions of Windows OS. To see if cURL is installed on Windows, go to Start -> Run and enter “cmd” (without quotes) into the dialog and press enter. To test cURL enter the following command:

curl -I http://www.4d.com

You should see HTTP response headers. The first line should be “HTTP/1.1 200 OK.” This means you have made a successful request to the www.4D.com URL using cURL.

If cURL is not available in your distribution’s package repository or you are running another operating system, you can find the right cURL package by following the download wizard at http://curl.haxx.se/dlwiz/. Simply select the “curl executable” option, input information about your computer and operating system and it will direct you to the correct file download. Once downloaded, extract any files in the archive to an easily accessible file (for example, c:\cURL on Windows).

Knowledge on how and where to install a command line executable is required.