0

I would like to be able to telnet, input login and password credentials and then execute commands once connected but my code seems to not continue after password is entered.

import getpass
import telnetlib

HOST = "172.25.1.1"
user = input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until(b"login: ")
tn.write(user.encode('utf-8') + "\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('utf-8') + "\n")

tn.write(b"command to be issued")
print(tn.read_all())

with this code I want to telnet, input login credentials, input password, and once connected issue a command

bgardne7
  • 91
  • 1
  • 11

1 Answers1

0

Looks like the problem was a timing issue, I needed to import time and add time.sleep(2) after issuing the command before print(tn.read_all()).

S.B
  • 13,077
  • 10
  • 22
  • 49
bgardne7
  • 91
  • 1
  • 11