George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Peter D Phan | 2f3a96e | 2021-07-29 12:12:02 -0500 | [diff] [blame] | 2 | |
| 3 | |
| 4 | import os |
| 5 | import sys |
| 6 | |
| 7 | # ---------Set sys.path for pluqin execution--------------------------------------- |
| 8 | # Absolute path to this plugin |
| 9 | abs_path = os.path.abspath(os.path.dirname(sys.argv[0])) |
| 10 | # full_path to plugins parent directory |
| 11 | full_path = abs_path.split('plugins')[0] |
| 12 | sys.path.append(full_path) |
| 13 | # Walk path and append to sys.path |
| 14 | for root, dirs, files in os.walk(full_path): |
| 15 | for found_dir in dirs: |
| 16 | sys.path.append(os.path.join(root, found_dir)) |
| 17 | |
| 18 | from telnet_utility import TelnetRemoteclient |
| 19 | |
| 20 | |
| 21 | def telnet_execute_cmd(hostname, |
| 22 | username, |
| 23 | password, |
| 24 | command, |
| 25 | timeout=60): |
| 26 | r""" |
| 27 | Description of argument(s): |
| 28 | |
| 29 | hostname Name/IP of the remote (targeting) host |
| 30 | username User on the remote host with access to FFCD files |
| 31 | password Password for user on remote host |
| 32 | command Command to run on remote host |
| 33 | timeout Time, in second, to wait for command completion |
| 34 | """ |
| 35 | telnet_remoteclient = TelnetRemoteclient(hostname, |
| 36 | username, |
| 37 | password) |
| 38 | result = '' |
| 39 | if telnet_remoteclient.tn_remoteclient_login(): |
| 40 | # result: stdout from remote host |
| 41 | result = \ |
| 42 | telnet_remoteclient.execute_command(command, timeout) |
| 43 | |
| 44 | # Close telnet session |
| 45 | if telnet_remoteclient: |
| 46 | telnet_remoteclient.tn_remoteclient_disconnect() |
| 47 | |
| 48 | return result |