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 04-12-2016, 09:10 AM
chrisfs chrisfs is offline
Registered User
 
Join Date: Nov 2015
Posts: 6
Python Login Script

Hello,

Do you have a python login script that'll support multiple vendors ( Cisco, ALU, Juniper ) to point a session to for authentication ?
Reply With Quote
  #2  
Old 04-12-2016, 11:50 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,309
Hello chrisfs,

What version of SecureCRT is installed?

What protocol do you use to connect to the devices?

Is the interaction when authenticating to them (ie: username, password prompts) the same between all vendors?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 04-12-2016, 02:14 PM
chrisfs chrisfs is offline
Registered User
 
Join Date: Nov 2015
Posts: 6
Hello,

Version 7.3.5 (x64 build 903), SSH and not identical prompts but I could manipulate it further if I had something to go on.
Reply With Quote
  #4  
Old 04-13-2016, 09:45 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,309
Hi chrisfs,

There are some example scripts included in the SecureCRT installation directory on Windows. However, the three simple login examples (example1,2,3) are VBScript.

First thing you will need to do is enable Display logon prompts in terminal window. You would probably want to do that in Default Session if changing existing sessions (or even to change Default Session which is the template for ad hoc connections or future saved sessions).

Here's an example of a simple Python login script:

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

def main():
  # turn on synchronous mode so we don't miss any data
  crt.Screen.Synchronous = True

  # Wait for a string that looks like "Username: " or "username: "
  crt.Screen.WaitForString("sername: ")

  # Send your username followed by a carriage return
  crt.Screen.Send("username\r")

  # Wait for a string that looks like "password: " or "Password: "
  crt.Screen.WaitForString("assword:")

  # Send your password followed by a carriage return
  crt.Screen.Send("password\r")

  # turn off synchronous mode to restore normal input processing
  crt.Screen.Synchronous = False

main()
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 04-15-2016, 08:47 AM
chrisfs chrisfs is offline
Registered User
 
Join Date: Nov 2015
Posts: 6
Thanks Brenda. No luck trying to log into a Juniper router... added " import SecureCRT at the top. I still get prompted for username in SecureCRT. appears to bypass the script.
Reply With Quote
  #6  
Old 04-15-2016, 02:57 PM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 810
Hi chrisfs.

What configuration change did you make to your session to
make it use the script?

what does your prompt look like?

JJH
Reply With Quote
  #7  
Old 04-18-2016, 07:51 AM
chrisfs chrisfs is offline
Registered User
 
Join Date: Nov 2015
Posts: 6
Hi,

So now I have it working on some Juniper's ( MX480's ) but with switch models it's not liking the carriage return after the username input. It'll print out in the prompt the " /r " as if it's not recognizing the symbol.
Reply With Quote
  #8  
Old 04-18-2016, 12:31 PM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 810
Hi Chrisfs.

I noticed that in your last message you are referring to a
forward slash r (/r), but the script that Brenda provided
uses backslash r (\r).

Are you really using /r?

If so, does changing it to \r resolve the issue?

Thanks

JJH
Reply With Quote
  #9  
Old 04-19-2016, 12:45 PM
chrisfs chrisfs is offline
Registered User
 
Join Date: Nov 2015
Posts: 6
Typo on here on my part, sorry about that. It's \r
Reply With Quote
  #10  
Old 04-20-2016, 10:05 AM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 810
Hi chrisfs.

Would you be able to post a copy of your script, so I can
see exactly how you have things working?

Since this is a public forum where you wouldn't want to post
sensitive data, please make sure to change any IP addresses
and passwords, but leave the full structure of the script
there.

Thanks

JJH
Reply With Quote
  #11  
Old 04-11-2020, 11:16 AM
Ulua Ulua is offline
Registered User
 
Join Date: May 2019
Posts: 5
Thumbs up The python login scripts the Vandyke support is great help

Guys,

I am new here and I am currently evaluating the latest SecureCrt 8.7. Our company just decided to use our NT login to access most of our switches. After migrating the access, I use the python login scripts that you provided and it made my life so much easier. I do not need to edit my access manually. Thank you again for your support.

Ulua
Reply With Quote
  #12  
Old 04-11-2020, 02:25 PM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 352
Hi Ulua,

Thanks for sharing your enthusiasm about the login script! I am glad to hear that automating your login process has made life easier.
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #13  
Old 04-13-2020, 12:06 PM
rcharger00 rcharger00 is offline
Registered User
 
Join Date: Apr 2020
Posts: 2
Python Script for automated login from linux host

Hi. I'm trying to use the below script to automate a login from a linux server to a cisco device. If I have not connected to the device before it prompts me to save the SSH keys (yes/no). My problem here is that I cannot get the script to act if the prompt appears or if it does not appear, bypass the "yes/no" prompt and proceed to the second half of the script.


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

def main():
	# turn on synchronous mode so we don't miss any data
	crt.Screen.Synchronous = True
	username = "cisco"
	password = "cisco"
	
	if(crt.Screen.WaitForString(("assword:") ==True):
		crt.Screen.Send(password+"\r")
		crt.Screen.WaitForString(">")
		crt.Screen.Send("enable\r")
		crt.Screen.WaitForString("assword:")
		crt.Screen.Send(password+"\r")
		crt.Screen.Send("\r\r\r")
	elif (crt.Screen.WaitForString(("(yse/no)?") ==True):
		crt.Screen.Send("yes\r")
		crt.Screen.WaitForString("assword:")
		crt.Screen.Send(password+"\r")
		crt.Screen.WaitForString(">")
		crt.Screen.Send("enable\r")
		crt.Screen.WaitForString("assword:")
		crt.Screen.Send(password+"\r")
		crt.Screen.Send("\r\r\r")
	crt.Screen.Synchronous = False
main()

Last edited by jdev; 04-13-2020 at 12:59 PM. Reason: Removed duplicate [/CODE] block
Reply With Quote
  #14  
Old 04-13-2020, 02:44 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 998
Hello "rcharger00",

The approach you're taking is flawed because once something has been displayed on the screen, it is no longer available for WaitForString() or any of the other WaitFor*/ReadString variants (data displayed in the terminal window has already been "cooked"; there's no waiting for something that has already arrived).

Only data that has not already been displayed to the screen is available for WaitFor*() and ReadString() functions that are part of the Screen object.

Knowing this, you must use the WaitForStrings() method -- passing an array of all possible strings that represent shell prompts (or other text triggers like (yes/no)) for which you would want to take different actions should they appear.

The approach that works is demonstrated in an existing example script that is one of many in our Script Examples page. The specific script is "Jump Host - Handle Secondary Host Connection Attempts". Use that script as your starting place, and see how far it gets you in your quest for automation.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #15  
Old 04-14-2020, 06:55 AM
rcharger00 rcharger00 is offline
Registered User
 
Join Date: Apr 2020
Posts: 2
Thumbs up Python Script for automated login from linux host

Thanks Jake! That was really helpful and I'm definitely much closer on this now. I am running in to one issue now basically distinguishing between a IOS and NXOS device for the login. I want to do it so that if I get prompted for ">" on IOS proceed with enable, the password, etc. and if I get prompted directly for "#" for a NXOS to just do a few carriage returns and exit. I can get it to handle the enable piece for matchindex 7 but running against a NXOS it never gets past 6 to proceed to 8 for a NXOS.

Code:
	vPossibleResponses = [\
		"-->",
		"$",
		"ogin:",
		"ame:",
		"(yes/no)?",
		"sword:",
		">",
		"#",
		"Permission Denied",
		"incorrect",
		"not known",
		"timed out",
		"onnection refused",
		"No route to host",]
		
		
		elif crt.Screen.MatchIndex == 6:
			crt.Screen.Send(password + "\r")
			
		elif crt.Screen.MatchIndex == 7:
			crt.Screen.Send("enable\r")
			crt.Screen.WaitForString("assword:")
			crt.Screen.Send(password + "\r")
			crt.Screen.Send("\r\r\r")
			
		elif crt.Screen.MatchIndex == 8:
			crt.Screen.Send("\r\r\r")
			return False
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 06:51 AM.