Python: Restart the router if there is no internet

Translation of the original in Catalan. Read it in: CatalàCastellano

Although a few days ago I changed my old Zyxel for a Cisco 837 at home, the ADSL line keeps hanging for unknown reasons. Because when data does not flow either up or down the ATM interfaces are up and everything seems to work correctly. So, I have had no choice but to make myself a small script with Python through which every 5min I check whether the pings to one of the OpenDNS servers come back. If that is not the case then it connects to the Cisco router and restarts it. Because I have done tests bringing the ATM interface down and up and there is no way. I haven't come up with a better idea than issuing a reload.

The script keeps a log file in /var/log/online.log and uses the pexpect module of Python. The rest of the things it uses are modules that are installed by default.

If anyone can make use of the script, you can download it: router.py.

3 comments

Comments from the old blog, as they were written. Comments are closed.

  1. sabueso

    Y que pasa si le pegas un toque a tu compania de telefono y les comentas el pollaco ? ;-)

  2. javivf

    nice python code! :)

  3. —

    [1]

    Pegarle un toque a telefónica...jajajajaj! paso tio és més fàcil fer l'script.