View Single Post
  #5  
Old 06-24-2018, 11:48 PM
winniec winniec is offline
Registered User
 
Join Date: Jun 2018
Posts: 5
Quote:
Originally Posted by bgagnon View Post
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.
Thank you. I have figured it out. Please check the below.

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")
Reply With Quote