Enes ERGUN
Enes ERGUN

Reputation: 35

Python step by step telnetlib output message

I am working on configuring an ip telephone using python.I can access the ip telephone via telnet, but i want use python.

my code:

user = "admin"
password = "admin"
tn = telnetlib.Telnet("192.168.1.191",23)
output = tn.read_until("Login:")
tn.write("admin".encode("ascii")+ b"\r\n")
tn.read_until("Password:")
tn.write("admin".encode("ascii")+ b"\r\n")
tn.write("help".encode("ascii")+ b"\r\n")
output = tn.read_all()
tn.close()
print output

but this does not work as it results in an infinite loop without printing any output.

Thanks for your help in advance.

Upvotes: 0

Views: 1003

Answers (1)

iLoveTux
iLoveTux

Reputation: 3625

as per the documentation read_all blocks until the connection is closed. You'd probably be better off figuring out what the last line of output should look like (a prompt maybe?) and using read_until like you've been doing. You can also look into read_eager, read_very_eager or read_some.

Upvotes: 1

Related Questions