标签:password 路由器 python router enable python 重启路由器
有一些服务,需要动态IP,所以我们用重启路由器的方法实现。人工重启不可选,用定时脚本执行即可。贴代码,每种路由器,提示不一样。需要路由器有telnet功能才行。
#!/usr/bin/env python # -*- coding: utf-8 -*- import telnetlib HOST = "192.168.1.1" USER = "admin" PASS = "admin" router = telnetlib.Telnet(HOST) router.set_debuglevel(2) router.read_until("Username:", 12) router.write(USER + "\r\n") router.read_until("Password:", 12) router.write(PASS + "\r\n") router.read_until("TP-LINK > ", 12) router.write("enable\r\n") router.read_until("Enter password: ", 12) router.write(PASS + "\r\n") router.read_until("TP-LINK # ", 12) router.write("sys reboot\r\n") router.read_until("Continue?", 12) router.write("Y\r\n") router.close() print "Done"
本文出自 “wolf_ribble@163.com” 博客,请务必保留此出处http://ribble.blog.51cto.com/3863110/1696802
标签:password 路由器 python router enable python 重启路由器
原文地址:http://ribble.blog.51cto.com/3863110/1696802