χρήστης
συνθηματικό
θυμήσου με
 
roomap
2010-07-21 17:25
 
raspberry memo for tv app
2017-08-12 14:16
CV
2012-09-20 14:43
linux-inside
2011-09-21 19:40
python powered
2011-09-20 19:52
 
I am very happy with  the tp-link load balancing router tl-r470t+ that multiplexes my adsl lines,although sometimes it gets stuck and does not provide dns access . For that reason I wrote a watchdog script for it that runs every minute via cron daemon . The script tries to resolve a dns record , and if it fails it reboots the rooter. Enjoy.

#!/usr/bin/env python

#By Thimios Katsoulis 2016-03
import sys
import telnetlib
import socket
import logging


HOST = "192.168.1.1"  #your router ip address
user = "admin"  # your administrator username here
password = "admin" # your normal password here
adminpassword = "admin"  # your admin password here
logfile = "/var/log/check_router.txt"  # change to your preferred location here
 

 

def checkDNS():
    try:
        ip = socket.gethostbyname('www.google.com')
        print "Internet Connection is ok"
        logging.info("Internet Connection is ok")
    except:
        logging.error("Internet Connection is not ok")
        rebootRouter()
  
  
def rebootRouter():
    logging.error( "Rebooting Router...")
    tn = telnetlib.Telnet(HOST)

    tn.read_until("Username:")
    tn.write(user + "\r\n")
    tn.read_until("Password:")
    tn.write(password + "\r\n")

    tn.write('enable\r\n')
    tn.write( adminpassword + '\r\n')
    tn.write('sys reboot\r\n')
    tn.write('y\r\n')
    tn.close()
    
    
if __name__ == '__main__':
    logging.basicConfig(filename = logfile , level=logging.WARNING ,  format='%(asctime)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
    checkDNS()