# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import telnetlib as Tn
import telnetlib as Tk
from tkinter import messagebox
import time
import os
import os.path
import logging
mode = 1
class tele():
def __init__(self):
self.tn = None
#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()
self.mode = 1
self.wmode = "w1"
#log
self.t_log = log()
#2.4G数据的写入
self.e5a_1 = "iwpriv ra0 e2p 5A=0100".encode()
self.e60_1 = "iwpriv ra0 e2p 60=0100".encode()
self.e66_1 = "iwpriv ra0 e2p 66=0100".encode()
self.e6C_1 = "iwpriv ra0 e2p 6C=0100".encode()
self.e5a_2 = "iwpriv ra0 e2p 5A=0300".encode()
self.e60_2 = "iwpriv ra0 e2p 60=0300".encode()
self.e66_2 = "iwpriv ra0 e2p 66=0300".encode()
self.e6C_2 = "iwpriv ra0 e2p 6C=0300".encode()
#5G数据写入
self.e94_2 = "iwpriv rai0 e2p 94=0300".encode()
self.e8A_2 = "iwpriv rai0 e2p 8A=0300".encode()
self.e76_2 = "iwpriv rai0 e2p 76=0300".encode()
self.e9E_2 = "iwpriv rai0 e2p 9E=0300".encode()
self.e94_1 = "iwpriv rai0 e2p 94=0100".encode()
self.e8A_1 = "iwpriv rai0 e2p 8A=0100".encode()
self.e76_1 = "iwpriv rai0 e2p 76=0100".encode()
self.e9E_1 = "iwpriv rai0 e2p 9E=0100".encode()
#数据读取
self.r5a_1 = "iwpriv ra0 e2p 5A".encode()
self.r60_1 = "iwpriv ra0 e2p 60".encode()
self.r66_1 = "iwpriv ra0 e2p 66".encode()
self.r6C_1 = "iwpriv ra0 e2p 6C".encode()
self.r5a_2 = "iwpriv ra0 e2p 5A".encode()
self.r60_2 = "iwpriv ra0 e2p 60".encode()
self.r66_2 = "iwpriv ra0 e2p 66".encode()
self.r6C_2 = "iwpriv ra0 e2p 6C".encode()
#5G
self.r94_2 = "iwpriv rai0 e2p 94".encode()
self.r8A_2 = "iwpriv rai0 e2p 8A".encode()
self.r76_2 = "iwpriv rai0 e2p 76".encode()
self.r9E_2 = "iwpriv rai0 e2p 9E".encode()
self.r94_1 = "iwpriv rai0 e2p 94".encode()
self.r8A_1 = "iwpriv rai0 e2p 8A".encode()
self.r76_1 = "iwpriv rai0 e2p 76".encode()
self.r9E_1 = "iwpriv rai0 e2p 9E".encode()
self.flag1 = "#".encode()
self.flag2 = "#".encode()
#wifi save
self.efuse = "iwpriv rai0 set efuseBufferModeWriteBack=1".encode()
self.WLan11ac_Common = "tcapi set WLan11ac_Common WriteBinToFlash 1".encode()
self.commit = "tcapi commit WLan11ac".encode()
self.efuse2 = "iwpriv ra0 set efuseBufferModeWriteBack=1".encode()
self.WLan11ac_Common2 = "tcapi set WLan_Common WriteBinToFlash 1".encode()
self.commit2 = "tcapi commit WLan".encode()
self.tcapi_save = "tcapi save".encode()
#reboot
self.reboot1 = "reboot".encode()
def login(self):
self.tn = Tn.Telnet("192.168.1.1", port=23, timeout=10)
# 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 -------\n")
# 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!!!\n")
def write_mode1(self):
try:
self.log_w("------------------write_mode1 0100---------------------\n")
self.log_w(self.e5a_1)
self.tn.write(self.e5a_1 + b'\n')
self.tn.write(self.e60_1 + b'\n')
self.tn.write(self.e66_1 + b'\n')
self.tn.write(self.e6C_1 + b'\n')
self.tn.write(self.e94_1 + b'\n')
self.tn.write(self.e8A_1 + b'\n')
self.tn.write(self.e76_1 + b'\n')
self.tn.write(self.e9E_1 + b'\n')
self.log_w("-----------------write_mode1 end!----------------------\n")
except Exception as e:
self.log_w("-----------------write_mode1 error!----------------------\n")
def write_mode2(self):
try:
self.log_w("-----------------write_mode2 0300----------------------\n")
self.log_w(self.e5a_2)
self.tn.write(self.e5a_2 + b'\n')
self.tn.write(self.e60_2 + b'\n')
self.tn.write(self.e66_2 + b'\n')
self.tn.write(self.e6C_2 + b'\n')
self.tn.write(self.e94_2 + b'\n')
self.tn.write(self.e8A_2 + b'\n')
self.tn.write(self.e76_2 + b'\n')
self.tn.write(self.e9E_2 + b'\n')
self.log_w("-----------------write_mode2 end!----------------------\n")
except Exception as e:
self.log_w("-----------------write_mode2 error!----------------------\n")
#messagebox.showinfo("the write_mode2 is error!\n")
def check_mode1(self):
try:
print("---------------------------check_mode1------------------------------\n")
self.log_w("-----------------check_mode1!----------------------\n")
self.tn.write(self.r5a_1 + b'\n')
sponse = self.tn.read_very_eager()
#sponse = self.tn.read_until(self.flag1,timeout=10)
print("the respon is :",sponse)
self.log_w(sponse)
self.tn.write(self.r60_1 + b'\n')
sponse = self.tn.read_until(self.flag1,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.tn.write(self.r66_1 + b'\n')
sponse = self.tn.read_until(self.flag1,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.tn.write(self.r6C_1 + b'\n')
sponse = self.tn.read_until(self.flag1,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.tn.write(self.r94_1 + b'\n')
sponse = self.tn.read_until(self.flag1,timeout=10)
print("the respon is :", sponse)
self.tn.write(self.r8A_1 + b'\n')
sponse = self.tn.read_until(self.flag1,timeout=10)
print("the respon is :", sponse)
self.tn.write(self.r76_1 + b'\n')
sponse = self.tn.read_until(self.flag1,timeout=10)
print("the respon is :", sponse)
self.tn.write(self.r9E_1 + b'\n')
sponse = self.tn.read_until(self.flag1,timeout=10)
print("the respon is :", sponse)
self.log_w("---------------------check_mode1 end!-------------------------------\n")
except Exception as e:
#messagebox.showinfo("error!","the check_mode1 is error!\n")
#文件写入
self.log_w("---------------------check_mode1 error!-------------------------------\n")
print("-----------check error!------------\n")
def check_mode2(self):
try:
print("-----check2-----")
self.log_w("-------------------check_mode2------------------------\n")
self.tn.write(self.r5a_2 + b'\n')
sponse = self.tn.read_until(self.flag2,timeout=10)
self.log_w(sponse)
print("the respon is :",sponse)
self.tn.write(self.r60_2 + b'\n')
sponse = self.tn.read_until(self.flag2,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.tn.write(self.r66_2 + b'\n')
sponse = self.tn.read_until(self.flag2,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.tn.write(self.r6C_2 + b'\n')
sponse = self.tn.read_until(self.flag2,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.tn.write(self.r94_2 + b'\n')
sponse = self.tn.read_until(self.flag2,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.tn.write(self.r8A_2 + b'\n')
sponse = self.tn.read_until(self.flag2,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.tn.write(self.r76_2 + b'\n')
sponse = self.tn.read_until(self.flag2,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.tn.write(self.r9E_2 + b'\n')
sponse = self.tn.read_until(self.flag2,timeout=10)
print("the respon is :", sponse)
self.log_w(sponse)
self.log_w("---------------------check_mode2 end!-------------------------------\n")
except Exception as e:
#messagebox.showinfo("error!","the check_mode1 is error!\n")
#文件写入
self.log_w("---------------------check_mode2 error!-------------------------------\n")
print("-----------check2 error!------------\n")
def check(self):
if self.mode == 1:
self.check_mode1()
elif self.mode == 2:
self.check_mode2()
def write(self):
try:
if self.mode == 1:
print("the mode is 1")
self.write_mode1()
elif self.mode == 2:
self.write_mode2()
except Exception as e:
messagebox.showinfo("error", "write error!\n")
def save_value(self):
self.log_w("---------------------save value!-------------------------------\n")
print("------------save value---------------\n")
try:
self.tn.write(self.efuse + b'\n')
self.tn.write(self.WLan11ac_Common + b'\n')
self.tn.write(self.commit + b'\n')
self.tn.write(self.efuse2 + b'\n')
self.tn.write(self.WLan11ac_Common2 + b'\n')
self.tn.write(self.commit2 + b'\n')
self.tn.write(self.tcapi_save + b'\n')
self.log_w("---------------------save value end!-------------------------------\n")
except Exception as e:
self.log_w("---------------------save value error!-------------------------------\n")
print("--------------save value error!--------------------")
def reboot(self):
try:
print("11")
self.log_w("reboot\n")
print("111")
self.tn.write(self.reboot1 + b'\n')
except Exception as e:
print("reboot error!\n")
def log_w(self,buff):
self.t_log.log_write(buff)
def end(self):
messagebox.showinfo("ok", "the fun is ok")
def close(self):
self.tn.close()
def test(self):
print("-----into-----\n")
class time_time():
def __int__(self):
self.time_flag = 1
def start_time(self):
time.sleep(8)
def start_save_time(self):
time.sleep(3)
def reboot_time(self):
time.sleep(120)
class log():
def __init__(self):
self.path = os.getcwd()
self.filename1 = self.path + '/' + 'log.txt'
logging.basicConfig(filename=self.filename1, level=logging.INFO)
# def get_path(self):
# self.path = os.getcwd()
# self.filename1 = self.path + '/' + 'log.txt'
# logging.basicConfig(filename=self.filename1, level=logging.INFO)
def log_write(self,log_info):
logging.info(log_info)
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
liyong = tele()
liyong_time = time_time()
liyong_time.start_time()
print("11111111")
while True:
if liyong.wmode == "w1":
print("-------------1 start -------------")
liyong.login()
liyong.write()
#liyong_time.start_time()
liyong.save_value()
#liyong.reboot()
liyong.close()
#liyong_time.reboot_time()
liyong.wmode = "c1"
print("-------------1 end -------------")
if liyong.wmode == "c1":
print("-------------2 start -------------")
liyong.login()
liyong.check()
liyong.wmode = "w2"
liyong.mode = 2
liyong.write()
#liyong_time.start_time()
liyong.save_value()
#liyong.reboot()
#liyong_time.reboot_time()
liyong.close()
liyong.wmode = "c2"
print("-------------2 end -------------")
if liyong.wmode == "c2":
print("-------------3 start -------------")
liyong.login()
liyong.check()
liyong.wmode = "w1"
liyong.mode = 1
liyong.write()
#liyong_time.start_time()
liyong.save_value()
#liyong.reboot()
#liyong_time.reboot_time()
liyong.close()
print("-------------3 end -------------")
wifi写值保存指令验证脚本
最新推荐文章于 2023-08-04 17:04:25 发布