Rebooting The Modem

BSNL Broadband is a very unreliable one most of the times because of the ADSL signal on a copper line and weather (yes, believe me it is!) – it is always bouncing and the DSL protocol renegotiated. This invariably means I can’t access my Synology DS214Play NAS server from anywhere outside my home. This is because my public IP address changes. I haven’t paid for a static IP as it costs a bomb and it is not reliable either because of the reason mentioned in the opening line of this post.

The synology has a built-in mechanism of refreshing the NAS’s public IP address and usually it is pretty reliable. All the above assumes that the TP-link modem (shown in picture for illustration only) is quite a robust one when it comes to ADSL protocol negotiation and frequent re-establishment of the PPPoE connection and getting a public IP address. Many a times, I have seen that the TPLink Modem hangs and not able to either establish a DSL link or obtain and renew a public IP. In such situations, I am left with no access to my NAS as mentioned before.

TPLINK - 8817 ADSL Modem

TPLINK – 8817 ADSL Modem

After pouring over the web and analyzing many options available – from replacing the modem with a better one  to rebooting the modem every now and then. Those solutions were impractical – changing the modem – because of costs. rebooting the modem regularly – 5mins, 1hr or 1day??

I came up with the below solution.

Rebooting/Resetting the Modem whenever

– there is a connectivity loss to an external device/node and sending email if reboot triggered.

– whenever an internal connectivity loss to one of the LAN nodes and sending email when reboot triggered.

– if we are redirected to a different page from the ISP and asking us to reboot the modem. Yes, this is done by BSNL after you reach the FUP limit.

I have observed that while the Modem is in the hung state, it’s CLI is still accessible via telnet and I am able to run administrative commands.

Scripts running on the NAS:

1. logip_reboot.sh  – A Shell script having the logic to determine the IP and reboot modem in case of failure. This is run every five minutes as a cron job.

#!/bin/bash
export MYIP=`cat /volume2/Aashman/Dropbox/aashman/logs/ip.me`
### curl ifconfig.me > /home/aashman/ip.me
### export NEW_IP=`cat ip.me`
### export NEW_IP=`curl ifconfig.me`
export NEW_IP=`curl http://myip.xname.org`

#Strings present in the BSNL redirect page.
export REDIR_MSG_1="Please wait while you are redirected"
export REDIR_MSG_2="ssssportal.war"

#To flag redirect page or not.
export IS_REDIR_MSG=0

#---------------------------------------------------------------
### export NEW_IP="<html>
### <head>
### <meta http-equiv=\"Refresh\" content=\"1; URL=http://172.30.3.136:8080/ssssportal.war/fup_4m-8g-512k.jsp\">
### <meta http-equiv=\"pragma\" content=\"no-cache\">
### </head>
### <body>
### Please wait while you are redirected ...
### </body>
### </html>"
#---------------------------------------------------------------

if [ -z "$NEW_IP" ]
then
 echo "NULL Returned from curl"
 echo "IP:NULL | `date`" >> /volume2/Aashman/Dropbox/aashman/logs/ipAdd.log
 exit
fi


#Debug , enable to debug.
### echo "$NEW_IP"
### echo " "
### echo "IS_REDIR_MSG:$IS_REDIR_MSG"

#Check if it is the redirect message.
case "$NEW_IP" in
 *$REDIR_MSG_1*)
 printf "\nSet for Reboot now, Found: \"$REDIR_MSG_1\"\n";
 export IS_REDIR_MSG=1;
 ;;
esac
case "$NEW_IP" in
 *$REDIR_MSG_2*)
 printf "\nSet for Reboot now, Found: \"$REDIR_MSG_2\"\n";
 export IS_REDIR_MSG=1;
 ;;
esac

if [ "$IS_REDIR_MSG" == 1 ]
then
 printf "\nRebooting Now, IS_REDIR_MSG: TRUE\n\n";
 sh /volume2/Aashman/Dropbox/aashman/scripts/syno/rebootModem.sh
 printf "\n\n_____________________________________________________________________\n"
 printf "\n"
 printf "|*******************************************************************|\n"
 printf "|*** Done Rebooting ADSL Modem - Try connecting after sometime   ***|\n"
 printf "|*******************************************************************|\n"
 printf "_____________________________________________________________________\n\n"
 # Send email here and log.
 echo "ADSL Modem Rebooted | `date` " >> /volume2/Aashman/Dropbox/aashman/logs/adslModemReboot.log
 echo -e "Subject:ADSL Modem Rebooted\n\n" "ADSL Modem Rebooted @ `date`" | sendmail -F "Aashman" -f home.aashman@gmail.com pradeepprakash@gmail.com
 exit
else
 printf "\nChecking if IP Address has changed and Logging, IS_REDIR_MSG: FALSE\n\n";
 echo $NEW_IP > /volume2/Aashman/Dropbox/aashman/logs/ip.me
 if [ "$MYIP" == "$NEW_IP" ]
 then
 echo "IP Has not changed"
 #echo "IP:$MYIP | `date`" >> /volume2/Aashman/Dropbox/aashman/logs/ipAdd.log
 #cat /volume2/Aashman/Dropbox/aashman/logs/ip.me | mail -s "Public IP Address Changed" pradeepprakash@gmail.com
 #echo -e "Subject:IP Address Not Changed\n\n" `cat /volume2/Aashman/Dropbox/aashman/logs/ip.me` | sendmail -F "Aashman" -f home.aashman@gmail.com pradeepprakash@gmail.com
 else
 echo "New IP is $NEW_IP"
 #cat /home/aashman/Dropbox/aashman/logs/ip.me | mutt -s "Public IP Address Changed" pradeepprakash@gmail.com
 #cat /volume2/Aashman/Dropbox/aashman/logs/ip.me | mail -s "Public IP Address Changed" pradeepprakash@gmail.com
 echo "IP:$NEW_IP | `date` **" >> /volume2/Aashman/Dropbox/aashman/logs/ipAdd.log
 echo -e "Subject:Public IP Address Changed\n\n" `cat /volume2/Aashman/Dropbox/aashman/logs/ip.me` | sendmail -F "Aashman" -f home.aashman@gmail.com pradeepprakash@gmail.com
 fi
fi

2. rebootModem.py – A Python script to reboot the modem. This is called by the above script.

import getpass
import sys
import telnetlib

HOST = "192.168.1.1"
#user = raw_input("Enter your remote account: ")
#password = getpass.getpass()
password = "aashmanf2$"

tn = telnetlib.Telnet(HOST)

#tn.read_until("login: ")
#tn.write(user + "\n")
if password:
 tn.read_until("Password: ")
 tn.write(password + "\n")

print "rebootModem.py - All set for rebooting\n Done!!"
tn.write("set reboot\n")
tn.write("exit\n")

print tn.read_all()

3. Crontab entries:

#minute hour mday month wday who command
*/5 * * * * root sh /volume2/Aashman/Dropbox/aashman/scripts/syno/logip_reboot.sh

Black Box In Aircrafts

We all know about the black box in aircrafts. Its been there for many years and little have changed about how it works. Whatever that has changed is only how you store the data, and what data is stored. Little has changed on how the black box is handled in times of crises – like a crash, emergency landing on water etc etc.

We all know that Navy aircrafts use the ejectable black boxes. The same should be implemented in commercial aircrafts too.

Most of the times, during emergency, accidents pilots look for a water body to land/crash land the aircraft. The blackbox should be implemented in such a way that when it comes in contact with water (for let’s say more than an hour), there should be mechanism built into the blackbox to non-destructively explode and cucoon itself inside a floatable, pressure proof, balloon, brightly colored and float on water as buoys. That way it is easier to retrieve the blackbox in a much quicker time than what is done today.
Just a thought…….

Crowd Searching

Crowd Searching:
We all know about the recent Malaysian Airlines #MH376 flight which has been missing.Even after 5 days, not much have surfaced – debris, floating remains, oil slicks etc. The area involved is huge. For comparison, it is like finding a pebble in a football field as someone pointed out.

In such situations, we should make use of all the technology we have at our disposal. One such thing is the “crowd searching” (may not be the right term) – deploy satellites with high resolution imaging capabilities and gather as many images as possible from the probable region and make it available in public domain server. Volunteers (general public) can then be asked to identify any unusual patterns which might be the crash site, debris etc. Internet can be used to reach out to huge number of people. Maximum number of clicks for a particular image might mean something (statistics rarely lie).

Then when we have the probable areas we can target a narrower region with as many vessels. The process might be quicker.

Just a thought.

This idea is not new, have been used from a long time to convert illegible texts and numbers into meaningful texts. Why can’t it be used for a search and rescue, might save some lives if we act quicker.