Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / 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 + " ")
router.read_until("Password:", 12)
router.write(PASS + " ")
router.read_until("TP-LINK > ", 12)
router.write("enable ")
router.read_until("Enter password: ", 12)
router.write(PASS + " ")
router.read_until("TP-LINK # ", 12)
router.write("sys reboot ")
router.read_until("Continue?", 12)
router.write("Y ")
router.close()
print "Done"下面关于Python的文章您也可能喜欢,不妨看看:Python:在指定目录下查找满足条件的文件  http://www.linuxidc.com/Linux/2015-08/121283.htmPython2.7.7源码分析  http://www.linuxidc.com/Linux/2015-08/121168.htm无需操作系统直接运行 Python 代码  http://www.linuxidc.com/Linux/2015-05/117357.htmCentOS上源码安装Python3.4  http://www.linuxidc.com/Linux/2015-01/111870.htm《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htmPython脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm在Ubuntu下用Python搭建桌面算法交易研究环境 http://www.linuxidc.com/Linux/2013-11/92534.htmPython 语言的发展简史 http://www.linuxidc.com/Linux/2014-09/107206.htmPython 的详细介绍:请点这里
Python 的下载地址:请点这里 本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-10/124024.htm