Getting Openwrt to connect automatically

Recently I had issues that my ISP (ACT Broadband) would drop the connection. This meant that we had to reconnect and log on to a portal to get connected. It was quite a pain so I wrote a script to do that and had the script run every 5 min.
To get it working you first need to install wget-nossl becuase the wget that comes with openwrt does not work. To install wget run the command

opkg install wget-nossl

The script for reconnecting is


if ! ping -c 1 google.com > /dev/null 2>&1
then
ifdown wan;
sleep 10;
ifup wan;
sleep 10;
wget -q -O /dev/null --post-data 'username=your_username&password=your_password&login=login' http://yourURL/;
echo "Reconnected";
else
echo "Fine";
fi

Update

Our ISP login form started taking 2 more parameters namely

p_auth (which is in the URL) and
userIP

To provide for these two parameters I had to change my code to the following:


#!/bin/sh
if ! ping -c 1 google.com > /dev/null 2>&1
then
ifdown wan;
sleep 10;
ifup wan;
sleep 10;
password="password";
username="username";
ip=`ifconfig eth0.2 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`;
url=`wget --quiet -O - http://portal.acttv.in | grep "<form.*POST"| awk -F "\"" '{print $2}'`;
postData="uname=$username&pword=$password&userIP=$ip";
wget -q -O /dev/null --post-data "$postData" $url;
echo "Reconnected";
else
echo "Fine";
fi

Leave a Reply

Your email address will not be published. Required fields are marked *