Huawei equipment on telnet
user-interface vty 0 4
authentication-mode aaa
user privilege level 15
protocol inbound all
telnet server enable
aaa
local-user test password cipher test
local-user test service-type telnet
python
# -*- coding: gb2312 -*-
import telnetlib
import time
HOST = "192.168.0.1"
user = "test"
password = "test"
def command(con, flag, str_=""):
data = con.read_until(flag.encode())
print(data.decode('gb2312', errors='ignore'), end="")
# errors -- Set up different error handling schemes . end="" Output does not wrap
con.write(str_.encode() + b"\n")
tn = telnetlib.Telnet(HOST, port=23)
command(tn, "Username:", user)
if password:
command(tn, "Password:", password)
command(tn, ">", "sys")
command(tn, "]", )
time.sleep(2)
tn.close()