ADSM modem checking / resetting

You may be on a ADSL and need to make sure that your modem is always operational. So the modem-connection needs to be tested and reset when the connection is down. There may be perfect systems out there to do this. I use a script to test and reset. The first one is a simple bash script performing a reset over the modem telnet, the second one is a python script that tests for a working concection and resets when needed.

Add to cron to test as often as you like, e.g. every 6 hours

Bash reset modem

#!/bin/bash

USERNAME='bigboss'
PDW='verysecret'
MODEM='10.1.1.1'

( echo open $MODEM
sleep 3
echo -e "$USERNAME\r\n"
sleep 3
echo -e "$PDW\r\n"
sleep 3
echo -e "system reboot\r\n"
sleep 5) | telnet

Python test and reset modem

#!/usr/bin/env python

# This script will ping to google.nl and if network is
# unreachable it will connect to the modem and reboot it.

# Original author: Boris Bolgradov
# Modified: FvW 20120505

import os
import commands
import pexpect

def adsl_reboot():
    p = pexpect.spawn('telnet 10.1.1.1')

    p.expect('Username : ')
    p.sendline('bigboss\r\n') # Sending Username.

    p.expect('Password : ')
    p.sendline('verysecret\r\n') # Sending Password.

    p.expect('=>') #check you user manual
    p.sendline('system reboot\r\n') # Sending command to the shell.

result = commands.getoutput("ping -c 1 google.nl")
if ((result.find("Unreachable") > -1) or (result.find("unknown") > -1)) :
    print 'Not connected! - Rebooting the modem.'
    adsl_reboot()
#else:
#    print 'Connected'



email: f_vanwestrenen @ umantec . nl

Here are a few more projects.