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



( 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 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')

    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")
if ((result.find("Unreachable") > -1) or (result.find("unknown") > -1)) :
    print 'Not connected! - Rebooting the modem.'
#    print 'Connected'

email: f_vanwestrenen @ umantec . nl

Here are a few more projects.