Jun-28-2019, 05:22 AM
Hi Pallavi,
I tried using your code and I get the following error.
Traceback (most recent call last):
File "telnet.py", line 18, in <module>
tn.read_until(b"Password: ") (indent)
NameError: name 'indent' is not defined
How can I fix it.?
I tried using your code and I get the following error.
Traceback (most recent call last):
File "telnet.py", line 18, in <module>
tn.read_until(b"Password: ") (indent)
NameError: name 'indent' is not defined
How can I fix it.?
(Jul-25-2018, 03:09 PM)pallavi Wrote:(May-04-2018, 10:27 PM)snagwekar Wrote: In my case all commands are executed but the print(tn.read_all().decode('ascii')) function do not print anything.
You can try this , it works for me, let me know if it did for you.
import getpass
import sys
import telnetlib
host = "10.0.0.10"
user = input("Enter Username:")
password = getpass.getpass()
tn = telnetlib.Telnet(host)
tn.read_until(b"Username:")
tn.write(user.encode("ascii")+ b"\n")
if password:
tn.read_until(b"Password:") (indent)
tn.write(password.encode("ascii")+b"\n") (indent)
tn.write(b"en \n")
tn.write(b"cisco\n")
tn.write(b"conf t\n")
tn.write(b"int loopback 1\n")
tn.write(b"ip add 1.1.1.1 255.255.255.255\n")
tn.write(b"end\n")
tn.write(b"exit\n")
print(tn.read_all().decode("ascii"))