Dynamically change IP address of destination host and connect to it

Version 1

    Verified Product Versions

    Wavelink Naurtech CETerm 5.7

    This script will dynamically change the IP address of the destination host and connect to it. It retrieves the configured host IP address x.Y.z.W. It then changes the IP address to x.22.z.250 and saves it to the configuration. The portion of the IP address marked in red is updated. It then invokes a connect operation which connects the session using the updated IP address.

     

    Note that several lines of the script are commented out. These show validation and debugging possibilities. Feel free to uncomment these and use as required in your scenario.

     

    /* Custom Connect Script */

    // For example, a terminal IP address 134.23.225.20 connects to host 134.22.225.250

     

     

    // USAGE: Assign a key to a separate script slot with the following contents

    //        to connect session 1:

    //          "CustomConnect(1);"

     

    function CustomConnect(session)

    {

        // Get device IP

        var ip = CETerm.GetProperty( "device.ipaddress" );

     

        // Split IP into separate parts

        var iparray = ip.split(".");

     

        // TODO: Add checking for valid IP address in your network

        //       For example:

        //     if (iparray[0] != 134)

        //     {

        //         OS.Alert("Invalid IP address of device.");

        //         return;

        //     }

     

        // Build host IP by changing values

        iparray[1] = 22;

        iparray[3] = 250;

     

        var hostip = iparray.join(".");

     

        // Set new host address

        CETerm.SetProperty( "session" + session + "connection.host", hostip );

     

        // DEBUG: Uncomment next line to check host IP

        //OS.Alert("hostip=" + hostip);

     

        // Switch to session

        CETerm.PostIDA( "IDA_SESSION_S" + session, session );

     

        // Connect session

        CETerm.PostIDA( "IDA_SESSION_CONNECT", session );

    }

     

    Here are the installation steps.

    1. Load the CustomConnect.js script into CETerm and mark it to "Load at Startup"
    2. Create a script to run the CustomConnect() function. This sample assumes you are going to connect session 1.
    3. Select an empty script slot (for example Script 2)
    4. Tap Edit and enter this text CustomConnect( 1 );
    5. Tap OK.

     

    To bind Script 2 to a key to connect to your host, you can select any key of your choice which will trigger a session connect.

    1. Open Session->Configure->Options->Configure Keybars and Keys
    2. Select the Edit Keymap tab.
    3. IMPORTANT: Select the "Unconnected" map for this key. This key will be active and pressed only when the session is unconnected.
    4. Tap New and select the desired key.
    5. Select the script slot you used above (for example Script 2).
    6. Tap OK to close all dialogs.