# $language = "Python" # $interface = "1.0" # ConnectToHostsInClipboard-One-per-Line-AdHocTabs.py.txt # # Last Modified: # 20 May, 2022 # - Updated to work with Python 3 or Python 2 # # 08 Jan, 2020 # - Initial revision # # Description: # - Shows how to instruct SecureCRT to establish ad hoc # connections to hosts listed one by one in the clibboard. # For example, if the following is in the clipboard... # host.a.domain # host.b.domain # host.c.domain # host.d.domain # host.e.domain # host.f.domain # # ...Or even, with auth: # ssh://user1:p4$$w0rd@192.168.1.1 # ssh://user2:p4$$w0rd@192.168.1.2 # ssh://user3:p4$$w0rd@192.168.1.3 # ssh://user4:p4$$w0rd@192.168.1.4 # ssh://user5:p4$$w0rd@192.168.1.5 # ssh://user6:p4$$w0rd@192.168.1.6 # # ... then running this script will cause SecureCRT # to connect to each host on a specific line in # separate tabs in the SecureCRT window. def Main(): # Get the clipbard contents strClipboard = crt.Clipboard.Text # Split by line (\r\n) EOL: vHosts = strClipboard.split("\r\n") # Iterate over each line expecting them to be a host # entity... for strHost in vHosts: # Trim spaces before/after/in the hostname/ip: strHost = strHost.replace(" ", "") # Ignore empty lines/data if not strHost == "": try: # Attempt to connect in a tab: crt.Session.ConnectInTab(strHost) except Exception as objException: # silently fail? # Complain bitterly? Yes. crt.Dialog.MessageBox("Failed to connect to host: {0}\r\n{1}".format( strHost, str(objException))) Main()