Reboot all routers via telnet in routers.txt file

📅 2021-07-26T10:16:24.000Z
👁️ 221 katselukertaa
🔓 Julkinen


import getpass
import telnetlib

with open('routers.txt') as f:
    lines = f.readlines()
    for line in lines:
        HOST = line.replace('\n', '')

        user = b"support\n"
        password = b"support\n"

        tn = telnetlib.Telnet(HOST)

        print(tn.read_until(b"Login: "))
        tn.write(user)

        print(tn.read_until(b"Password: "))
        tn.write(password)

        tn.write(b"reboot\n")
        tn.write(b"exit\n")

        print(tn.read_all())

        print("Rebooted host:", HOST)