Telnet login in python

337 views Asked by At

I have been trying to make a automated python login system, but I keep getting this error:

Traceback (most recent call last):   File "/home/kali/py.py", line 14, in <module>
    tn.read_until(b"Password: ")   File "/usr/lib/python3.9/telnetlib.py", line 329, in read_until
    return self.read_very_lazy()   File "/usr/lib/python3.9/telnetlib.py", line 405, in read_very_lazy
    raise EOFError('telnet connection closed') EOFError: telnet connection closed

The code is:

import telnetlib
import getpass


HOST = "127.0.0.1" #not really, I used a real telnet ip
user = input("USERNAME: ")
password = getpass.getpass()

tn = telnetlib.Telnet()
tn.open(HOST)

tn.read_until(b"login: ")
tn.write(user.encode("ascii")+b"\n")
tn.read_until(b"Password: ")
tn.write(password.encode("ascii")+b"\n")
tn.write(b"exit\n")
print(tn.read_all())
tn.close()

I REALLY need help with this, but if you don't know how, could someone please tell me how to do it in terminal, like a all in one command? telnet --user admin --password 1234 127.0.0.1 or something like that.

0

There are 0 answers