I'm trying to telnet to my box. When I do this in DOS it's simple, I even have 
a blinking cursor for me to type in commands for each response. Not so for 
python. I have a dictionary "user_acct" which has the username and password in 
it. My box is interactive, I must be able to type in commands and I don't know 
how to do this in python. Pleasehelp me any way you can.
1st prompt = Username:2nd prompt = Password:

After this my box's output looks like this:Last Login Date      : May 24 2016 
09:42:08
Last Login Type      : IP Session(CLI)
Login Failures       : 0 (Since Last Login)
                     : 0 (Total for Account)
TA5000>then I type en and get
TA5000# then I type conf t and getTA5000(config)#
My code is below:

import getpass
import sys
import telnetlibusername = input()
password = input()
tid = 'TA5000'
first_prompt = '>' # type 'en' at this prompt
second_prompt = '#' # type 'conf t' at this prompt
third_prompt = '(config)'
prompt1 = tid + first_prompt
prompt2 = tid + second_prompt
prompt3 = tid + third_prompt + second_prompt
user_acct = 
{'ADMIN':'PASSWORD','ADTRAN':'BOSCO','READONLY':'PASSWORD','READWRITE':'PASSWORD','TEST':'PASSWORD','guest':'PASSWORD','':'PASSWORD'}
host = "10.51.18.88"
#username = "ADMIN" + newline
#password = "PASSWORD" + newline
tn = telnetlib.Telnet(host,"23")
open()
tn.read_until("Username: ")
tn.write(username)
tn.read_until("Password: ")
tn.write(password)if username in user_acct and password == user_acct[username]: 
     print(prompt1 + "Enter en at this prompt" +"\n")
     print(prompt2 + "Enter conf t at this prompt" + "\n")
     print(prompt3 + "\n")
else:
     
     print('Invalid Login... Please Try Again')close()



...you cannot direct the wind but you can adjust your sails...  Angelia Spencer 
(Angie)
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to