Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-21-2018, 07:25 AM
winniec winniec is offline
Registered User
 
Join Date: Jun 2018
Posts: 5
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")
Reply With Quote
 

Tags
next tab , password , prompt


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 05:50 PM.