Reboot all routers via telnet in routers.txt file

26. heinäkuuta 2021 | 119 näyttökertaa

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)