有一些服务,需要动态IP,所以我们用重启路由器的方法实现。人工重启不可选,用定时脚本执行即可。贴代码,每种路由器,提示不一样。需要路由器有telnet功能才行。
\#!/usr/bin/env [Python](https://www.linuxidc.com/topicnews.aspx?tid=17)
\# -*- 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"
以上就是良许教程网为各位朋友分享的Linu系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你 !