歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Python 實現重啟路由器

Python 實現重啟路由器

日期:2017/3/1 9:21:23   编辑:Linux編程

有一些服務,需要動態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"

下面關於Python的文章您也可能喜歡,不妨看看:

Python:在指定目錄下查找滿足條件的文件 http://www.linuxidc.com/Linux/2015-08/121283.htm

Python2.7.7源碼分析 http://www.linuxidc.com/Linux/2015-08/121168.htm

無需操作系統直接運行 Python 代碼 http://www.linuxidc.com/Linux/2015-05/117357.htm

CentOS上源碼安裝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.htm

Python腳本獲取Linux系統信息 http://www.linuxidc.com/Linux/2013-08/88531.htm

在Ubuntu下用Python搭建桌面算法交易研究環境 http://www.linuxidc.com/Linux/2013-11/92534.htm

Python 語言的發展簡史 http://www.linuxidc.com/Linux/2014-09/107206.htm

Python 的詳細介紹:請點這裡
Python 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved