import telnetlib as Tn
import telnetlib as Tk
from tkinter import messagebox
class tele():
def __init__(self):
# self.tn = Tn.Telnet("192.168.1.1",port=23,timeout=10)
self.tn =Tn.Telnet("192.168.1.1",port=23,timeout=10)
self.accout = "telecomadmin".encode()
self.password = "nE7jA%5m".encode()
self.ifconfig_2 = "ifconfig ra0 down".encode()
self.ifconfig_2_up = "ifconfig ra0 up".encode()
self.name = "tc login:".encode()
def login(self):
#tn = Tn.Telnet("192.168.1.1",port=23,timeout=10)
print(self.accout)
try:
respon = self.tn.read_until(self.name)
except Exception as e:
print("------respon is error -------")
#print("the is :",respon)
try:
self.tn.write(self.accout+b'\n'+self.password+b'\n')
except Exception as e:
messagebox.showinfo("error","the login error!!!")
def write(self):
try:
self.tn.write(self.ifconfig_2+b'\n')
except Exception as e:
messagebox.showinfo("error","ifconfig error!")
def end(self):
messagebox.showinfo("ok","the fun is ok")
def close(self):
self.tn.close()
def test(self):
print("-----into-----")
t = tele()
t.login()
t.write()
t.end()
t.close()