Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-29-2013, 09:17 PM
jarobert jarobert is offline
Registered User
 
Join Date: Sep 2013
Posts: 1
Newbie Help Python Scripting

Hello,

I am new to scripting and python. I normally copy paste. So please forgive. I have been able to compile this little script for my self, but want to make it little better.

What I would like to accomplish is the following:

if ssh fails, to attempt to telnet using the stored user and password, should that fail to connect it will abort. If it connects and gets to a ">" it will enter the enable password, using the saved variable. This will be used to help automate logins to cisco devices. Any help is welcomed. Even resources to help the programming challenged are welcome.


Code:
# $language = "python"
# $interface = "1.0"

# This automatically generated script may need to be
# edited in order to work correctly.

def Main():
	#Ask user the host/IP address
	host = crt.Dialog.Prompt("Enter Host/IP address to connect to:")
	user = crt.Dialog.Prompt(" Enter Username" + (host))
	passwd = crt.Dialog.Prompt("Enter your password:", "Logon Script", "", True)
	crt.Screen.Synchronous = True
	crt.Screen.Send("ssh -o StrictHostKeyChecking=no -o PreferredAuthentications=password -l" + (user) + " " + (host) + chr(13))
	#If "~]$" then perform telnet, if telnet fails, script aborts. 
	crt.Screen.WaitForString("assword: ", 10)
	crt.Screen.Send((passwd) + chr(13))
	# if ">" is at the prompt, then type "enable" and enter passwd.
	crt.Screen.Synchronous = False
Main()
Reply With Quote
  #2  
Old 09-30-2013, 08:32 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,313
Hello jarobert,

What version of SecureCRT are you using?

Have you already connected to a jumphost or gateway server, since the command you are sending first is (essentially) ssh host?

What do the various "if" scenarios (as shown in the comments) represent?


Quote:
#If "~]$" then perform telnet, if telnet fails, script aborts.
You will probably need to configure an array of possibilities for failure, such as:

Code:
# Modify the "$", the "]#", and/or the "->" in the array below to reflect
# the variety of legitimate shell prompts you would expect to see when
# authentication is successful to one of your remote machines.
vPossibleResponses = [\
    "->",
    "]#",
    "$",
    "ogin:",
    "sword:",
    "ogin incorrect",
    "authentication failed"]
Then you would take the direction dictated by whatever the response was.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:39 PM.