1e7e9171eSGeorge Keishing#!/usr/bin/env python3 22f3a96edSPeter D Phan 32f3a96edSPeter D Phan 42f3a96edSPeter D Phanimport os 52f3a96edSPeter D Phanimport sys 62f3a96edSPeter D Phan 72f3a96edSPeter D Phan# ---------Set sys.path for pluqin execution--------------------------------------- 82f3a96edSPeter D Phan# Absolute path to this plugin 92f3a96edSPeter D Phanabs_path = os.path.abspath(os.path.dirname(sys.argv[0])) 102f3a96edSPeter D Phan# full_path to plugins parent directory 11*20f38712SPatrick Williamsfull_path = abs_path.split("plugins")[0] 122f3a96edSPeter D Phansys.path.append(full_path) 132f3a96edSPeter D Phan# Walk path and append to sys.path 142f3a96edSPeter D Phanfor root, dirs, files in os.walk(full_path): 152f3a96edSPeter D Phan for found_dir in dirs: 162f3a96edSPeter D Phan sys.path.append(os.path.join(root, found_dir)) 172f3a96edSPeter D Phan 1809679890SGeorge Keishingfrom telnet_utility import TelnetRemoteclient # NOQA 1937c58c8cSGeorge Keishing 202f3a96edSPeter D Phan 21*20f38712SPatrick Williamsdef telnet_execute_cmd(hostname, username, password, command, timeout=60): 222f3a96edSPeter D Phan r""" 232f3a96edSPeter D Phan Description of argument(s): 242f3a96edSPeter D Phan 252f3a96edSPeter D Phan hostname Name/IP of the remote (targeting) host 262f3a96edSPeter D Phan username User on the remote host with access to FFCD files 272f3a96edSPeter D Phan password Password for user on remote host 282f3a96edSPeter D Phan command Command to run on remote host 292f3a96edSPeter D Phan timeout Time, in second, to wait for command completion 302f3a96edSPeter D Phan """ 31*20f38712SPatrick Williams telnet_remoteclient = TelnetRemoteclient(hostname, username, password) 32*20f38712SPatrick Williams result = "" 332f3a96edSPeter D Phan if telnet_remoteclient.tn_remoteclient_login(): 342f3a96edSPeter D Phan # result: stdout from remote host 35*20f38712SPatrick Williams result = telnet_remoteclient.execute_command(command, timeout) 362f3a96edSPeter D Phan 372f3a96edSPeter D Phan # Close telnet session 382f3a96edSPeter D Phan if telnet_remoteclient: 392f3a96edSPeter D Phan telnet_remoteclient.tn_remoteclient_disconnect() 402f3a96edSPeter D Phan 412f3a96edSPeter D Phan return result 42