PluginConnectivityExamples
Contents
Connectivity examples
This section collects common examples. Connectivity is actual two plugins one for handling ssh and telnet and one for handling ftp.
On linux and unix only root can bind ports below 1024. This can be remedied in a number of ways. E.g. by setting capabilities on the java executable or by using some suitable NAT rule. Setting capabilities are supported in java 1.7.
Create a ssh session
/* * Connect to ipaddress and store result of executing whoami on the remote host */ SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); importPackage( Packages.dk.autodrive.plugins ); var f = ''+at.loadJS("stdfunc.js"); eval(f); theObj = getPlugin(Packages.dk.autodrive.plugins.AD_Connectivity_Commands); // Using default ssh port 22 theObj.createSSHSession('ipaddress','username','password'); var result = theObj.shellSend('whoami'); // Using custom ssh port 2222 theObj.createSSHSession('ipaddress',2222,'username','password'); result = theObj.shellSend('whoami'); ENDSCRIPT
Connect to jumpserver
This is useful if the setup requires to establish a tunnel to a remote host which is defined only in the context of a network reachable from the jumpserver.
The example shows forwarding one port, however, it is also possible to forward multiple ports.
SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); importPackage( Packages.dk.autodrive.plugins ); var f = ''+at.loadJS("stdfunc.js"); eval(f); theObj = getPlugin(Packages.dk.autodrive.plugins.AD_Connectivity_Commands); theObj.jumpServerConnect('username','password','jumpserveripaddress','localIP','localPort','remoteHostIP','remoteHostPort'); ENDSCRIPT
Connect to a remote host
This example shows how to create portforwards to servers connected to a remote host defined only i a local network reachable trhough a jumpserver.
The example shows forwarding one port, however, it is also possible to forward multiple ports. Please consult interface for all options.
SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); importPackage( Packages.dk.autodrive.plugins ); var f = ''+at.loadJS("stdfunc.js"); eval(f); theObj = getPlugin(Packages.dk.autodrive.plugins.AD_Connectivity_Commands); // Imagine a ssh portforward to some remote hidden behind a jumpserver // localPort = remoteHostPort = 22 theObj.jumpServerConnect('username','password','jumpserveripaddress','localIP', 'localPort','remoteHostIP','remoteHostPort'); // To forward ports only reachable from the remote host we create an additinal tunnel within the jumpserver tunnel theObj.serverInstanceConnect('username','password','localIP', 'fromLocalIp', 'fromLocalPort, 'toRemoteIp', 'toRemotePort') ENDSCRIPT
Portforwarding
See Connect to a remote host and Connect to jumpserver
Setting up a socks proxy
SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); importPackage( Packages.dk.autodrive.plugins ); var f = ''+at.loadJS("stdfunc.js"); eval(f); theObj = getPlugin(Packages.dk.autodrive.plugins.AD_Connectivity_Commands); // Setup a socks proxy on localhost port 34295 theObj.declareSocksProxy('127.0.0.1', 34295) // Further communications like telnet or web service calls happens through the socks proxy ENDSCRIPT
Socket timeout
SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); importPackage( Packages.dk.autodrive.plugins ); var f = ''+at.loadJS("stdfunc.js"); eval(f); theObj = getPlugin(Packages.dk.autodrive.plugins.AD_Connectivity_Commands); // Default timeout is 30 seconds. Here it is set to 10 seconds theObj.setSocketTimeout(10); ENDSCRIPT
Command timeout
SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); importPackage( Packages.dk.autodrive.plugins ); var f = ''+at.loadJS("stdfunc.js"); eval(f); theObj = getPlugin(Packages.dk.autodrive.plugins.AD_Connectivity_Commands); // Default timeout is 100 milliseconds. Here it is set to 300 milliseconds theObj.setCommandTimeout(300); ENDSCRIPT
Telnet
SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); importPackage( Packages.dk.autodrive.plugins ); var f = ''+at.loadJS("stdfunc.js"); eval(f); theObj = getPlugin(Packages.dk.autodrive.plugins.AD_Connectivity_Commands); // Performing telnet which throws exceptions in case of errors theObj.telnet('fromLocalIp', fromLocalPort) ENDSCRIPT
FTP
SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); importPackage( Packages.dk.autodrive.plugins ); var f = ''+at.loadJS("stdfunc.js"); eval(f); theObj = getPlugin(Packages.dk.autodrive.plugins.AD_Connectivity_Commands); // normal ftp theObj.ftp('serverIP', 'clientIP', ctlPort, 'path to cmdscriptfile', 'inputDir', 'outputDir') ENDSCRIPT