#!/usr/bin/python3
import telnetlib
import time
HOST = "192.168.10.5" # ip adress of whatever you want to control
telnet = telnetlib.Telnet(HOST)
time.sleep(1)
telnet.read_some()
telnet.write(b"admin\n")
telnet.read_until(b"Password:",3) # wait for Password: before writing password
telnet.write(b"yourpass\n")
telnet.read_until(b"<H3C>",10) # wait for "<H3C>" before writing command
telnet.write(b"reboot\r\n")
telnet.read_until(b"[Y/N]",10) # wait for "[Y/N]" (commands have been executed)
telnet.write(b"y\r\n") # all done, exit and close
time.sleep(3)
telnet.close()