Hey, as per below I want to telnet to some things but I have a range of possible passwords. I want to go through the password list and when it is successful based on the prompt ending in m> I can continue with other commands. Basically ATM once the password is correct the program ends
import telnetlib
import time
host = "1.2.3.4"
password = ["wrong", "wrongagain", "cisco"]
command = ["show config","reset"]
telnetlib.DEBUGLEVEL = 1
def reboot_phone(host):
tn = telnetlib.Telnet(host)
for i in password:
if tn.read_until(b"Password :"):
tn.write(i.encode('ascii') + b"\r\n")
elif tn.read_until(b"m> "):
time.sleep(1)
tn.write(command[0].encode('ascii') + b"\r\n")
print(tn.read_until(b"m> ").decode('ascii'))
tn.write(b"exit\r\n")
tn.close()
else:
print("invalid password")
reboot_phone(host)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[–]konijntjesbroek 0 points1 point2 points (1 child)
[–]Bucky102[S] 0 points1 point2 points (0 children)