#1
|
|||
|
|||
Python The new password can not pass on the next tab
This is the purpose of the script:
1. Read the ip address of the SessionList.txt e.g: SessionList.txt 192.168.11.165 192.168.11.161 2. Connect each ip address via a separate tab. 3. Prompt user/password for the user to login. After that, the two variables can pass on the remaining tab. The user only need to input once. However, I want the user/password window pop up again if I input a wrong user/pssword the first time. I tried to accomplish the task like this. However, it could not pass to the second tab....Could you please let me know why? Thank you! Code:
import re import os import subprocess SCRIPT_TAB=crt.GetScriptTab() SCRIPT_TAB.Screen.Synchronous=True SCRIPT_TAB.Screen.IgnoreEscape = True def CreateObjTab(user,password,session): objNewTab = crt.Session.ConnectInTab("/TELNET %s 23" % session) objNewTab.Screen.WaitForString("login:") objNewTab.Screen.Send(user + "\r") objNewTab.Screen.WaitForString("Password:") objNewTab.Screen.Send(password + "\r") while not objNewTab.Screen.WaitForString(">",3): x = Parent(crt.Dialog.Prompt("Enter user name:", "Login", "", False), crt.Dialog.Prompt("Enter password:", "Login", "", True)) user = x.u password = x.p objNewTab.Screen.WaitForString("login:") objNewTab.Screen.Send(user + "\r") objNewTab.Screen.WaitForString("Password:") objNewTab.Screen.Send(password + "\r") objNewTab.Screen.Send("enable\r") objNewTab.Screen.WaitForString("Password:") objNewTab.Screen.Send("casa\r") objNewTab.Screen.WaitForString("#") class Parent(): def __init__(self, user, password): self.u=user self.p=password def AutoConnectTab(file): ###Auto connect sessions from a txt ####This is to Open the "SessionList.txt" and get a list of the ip address if not os.path.exists(file): return sessionFile = open(file, "r") sessionArray = [] for line in sessionFile: session = line.strip() if session: sessionArray.append(session) sessionFile.close() # Receive variable x = Parent(crt.Dialog.Prompt("Enter user name:", "Login", "", False), crt.Dialog.Prompt("Enter password:", "Login", "", True)) user = x.u password = x.p for session in sessionArray[0:]: try: CreateObjTab(user,password,session) except ScriptError: pass if not SCRIPT_TAB.Session.Connected: return AutoConnectTab(os.getcwd()+"\SessionList.txt") |
#2
|
|||
|
|||
Hi winniec,
Please elaborate on the behavior: Quote:
Or was the script still running? (ie: Is Cancel available from the Script menu and if so, when you choose it, what line of the script is indicated?)
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
Quote:
In the next tab, the window pops up again and I need to input the user/password again. Thank you very much for you help. |
#4
|
|||
|
|||
Hi winniec,
It's clear your Python knowledge exceeds mine (use of classes and such), so I am afraid I won't be much help figuring out where the issue is in that script. ![]() You might just use the tried and true debug method of sprinkling in some message boxes so that you can be sure the variables contain what you think they should (previously entered credentials). If I get some free cycles and can determine the cause, I will post here. My initial suspicion is the prompt for that connection maybe does not end in the character you think it does? while not objNewTab.Screen.WaitForString(">",3):That would seem to bring up the prompt for credentials when it's not expected.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 Last edited by bgagnon; 06-22-2018 at 08:25 AM. |
#5
|
|||
|
|||
Quote:
Code:
class Account: def __init__(self): self.user = crt.Dialog.Prompt("Enter user name:", "Login", "", False) self.password = crt.Dialog.Prompt("Enter password:", "Login", "", True) def CreateObjTab(user, password, session): objNewTab = crt.Session.ConnectInTab("/TELNET %s 23" % session) objNewTab.Screen.WaitForString("login:") objNewTab.Screen.Send(user + "\r") objNewTab.Screen.WaitForString("Password:") objNewTab.Screen.Send(password + "\r") while not objNewTab.Screen.WaitForString(">", 3): user = crt.Dialog.Prompt("Enter user name:", "Login", "", False) password = crt.Dialog.Prompt("Enter password:", "Login", "", True) objNewTab.Screen.WaitForString("login:") objNewTab.Screen.Send(user + "\r") objNewTab.Screen.WaitForString("Password:") objNewTab.Screen.Send(password + "\r") return user, password objNewTab.Screen.Send("enable\r") objNewTab.Screen.WaitForString("Password:") objNewTab.Screen.Send("casa\r") objNewTab.Screen.WaitForString("#") def AutoConnectTab(file): ###Auto connect sessions from a txt ####This is to Open the "SessionList.txt" and get a list of the ip address if not os.path.exists(file): return sessionFile = open(file, "r") sessionArray = [] for line in sessionFile: session = line.strip() if session: sessionArray.append(session) sessionFile.close() # Receive variable account = Account() account.user,account.password =CreateObjTab(account.user, account.password, sessionArray[0]) for session in sessionArray[1:]: try: CreateObjTab(account.user, account.password, session) except ScriptError: pass if not SCRIPT_TAB.Session.Connected: return AutoConnectTab(os.getcwd() + "\SessionList.txt") |
#6
|
|||
|
|||
Hi winniec,
Awesome, thanks for posting the update! Have a great week. ![]()
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Tags |
next tab , password , prompt |
Thread Tools | |
Display Modes | Rate This Thread |
|
|