Python program to connect to console via telnetlib
Hi I am a tcl person trying to do a day to day activity in python in order
to get familiarity with the new gen language what python is compared to
tcl . No one want tcl anymore :)
Ok , So I have come with a code to automate this typical activity I would
do to clear a console line . $ telnet 172.28.247.240 Trying
172.28.247.240... Escape character is '^]'. User Access Verification
Password: labc-f18-ts>en Password: labc-f18-ts#clear line 66 [confirm]
[OK]
My Code looks like this : But I dont seem to get any output and dont know
if it actually cleared the lines (no output whatsoever) . please help.
import getpass
import sys
import telnetlib
a_tuple = [ ('172.28.247.240' , 66)]
HOST = j[0]
user = "admin"
password = "1234"
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.read_until("labc-f18-ts>")
tn.write ("en" +"\n")
tn.read_until("labc-f18-ts#")
tn.write("clear line %d" %j[1])
tn.write("exit\n")
sess_op = tn.read_all()
print sess_op
Also Is there anything like pexpect that I should be working with rather ?
No comments:
Post a Comment