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 18.104.22.168 connects to host 22.214.171.124
// USAGE: Assign a key to a separate script slot with the following contents
// to connect session 1:
// 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 != 134)
// OS.Alert("Invalid IP address of device.");
// Build host IP by changing values
iparray = 22;
iparray = 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.
- Load the CustomConnect.js script into CETerm and mark it to "Load at Startup"
- Create a script to run the CustomConnect() function. This sample assumes you are going to connect session 1.
- Select an empty script slot (for example Script 2)
- Tap Edit and enter this text CustomConnect( 1 );
- 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.
- Open Session->Configure->Options->Configure Keybars and Keys
- Select the Edit Keymap tab.
- IMPORTANT: Select the "Unconnected" map for this key. This key will be active and pressed only when the session is unconnected.
- Tap New and select the desired key.
- Select the script slot you used above (for example Script 2).
- Tap OK to close all dialogs.