过程参考
小米路由器mini刷Breed,安装固件教程_SUNYZ0525的博客-CSDN博客_小米mini刷机
以及
小米路由器mini刷padavan - 哔哩哔哩
整合了一下刷机过程,可以略去很多繁琐的刷机步骤,无需U盘刷机
步骤1:根据上面的博客链接,将小米路由器mini系统刷成开发版,版本选用的是B站链接中的2.7.11版本
步骤2:根据b站教程,从开发版下的系统控制台的网址中获取stok
步骤3:将stok输入到自动化的代码中,等待刷机完成
步骤4:输入192.168.1.1进入breed
(注意,其他需要用到的文件放在py代码同目录下,名为files的文件中,也可以根据需要对代码进行修改)
自动化代码如下:
import webbrowser
import time
import paramiko
from scp import SCPClientdef upload_file(ftp, remotepath, localpath):bufsize = 1024fp = open(localpath, 'rb')ftp.storbinary('STOR ' + remotepath, fp, bufsize)ftp.set_debuglevel(0)fp.close()stock = 'enter your stok here'code1 = "http://192.168.31.1/cgi-bin/luci/;stok={}/api/xqnetwork/set_wifi_ap?ssid=tianbao&encryption=NONE&enctype=NONE&channel=1%3Bnvram%20set%20ssh%5Fen%3D1%3B%20nvram%20commit".format(stock)code2 = "http://192.168.31.1/cgi-bin/luci/;stok={}/api/xqnetwork/set_wifi_ap?ssid=tianbao&encryption=NONE&enctype=NONE&channel=1%3Bsed%20%2Di%20%22%3Ax%3AN%3As%2Fif%20%5C%5B%2E%2A%5C%3B%20then%5Cn%2E%2Areturn%200%5Cn%2E%2Afi%2F%23tb%2F%3Bb%20x%22%20%2Fetc%2Finit.d%".format(stock)code3 = "http://192.168.31.1/cgi-bin/luci/;stok={}/api/xqnetwork/set_wifi_ap?ssid=tianbao&encryption=NONE&enctype=NONE&channel=1%3B%2Fetc%2Finit.d%2Fdropbear%20start".format(stock)code4 = "http://192.168.31.1/cgi-bin/luci/;stok={}/api/xqsystem/set_name_password?oldPwd=00000000&newPwd=00000000".format(stock)webbrowser.open(code1)
time.sleep(60)
print("code1 done.")webbrowser.open(code2)
time.sleep(30)
print("code2 done.")webbrowser.open(code3)
time.sleep(30)
print("code3 done.")webbrowser.open(code4)
time.sleep(30)
print("code4 done.")print("start ssh connect.")
ssh = paramiko.SSHClient() #创建SSH对象
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())#允许连接不在know_hosts文件中的主机
ssh.connect(hostname='192.168.31.1', port=22, username='root', password='00000000')#连接服务器
scp = SCPClient(ssh.get_transport())
scp.put("files/breed-mt7620-xiaomi-mini.bin", recursive=True, remote_path='/tmp/')print("file loading done.")print("execute command.")ssh.exec_command(command='cd /tmp;mtd -r write breed-mt7620-xiaomi-mini.bin Bootloader')scp.close()
ssh.close()
print("connect close.")
print("restarting...")
time.sleep(180)
print("restart done")