Skip to main content

Automating web login using OpenWRT

If you are plagued by having to put up with an Internet Service Provider that insists that you login through their webpage everyday before you use the internet, then read on for an solution.

I use Reliance Broadband in Mumbai, India. Whenever you try to use the internet,you need to first login through their portal page - no matter what URL you type, you will be first redirected to their login webpage where you type in your username and password before you can begin surfing the internet. Even Windows will complain with a "Additional log on information may be required" popup. Also Reliance insists that you login again 24 hours later. To overcome this PITA, I flashed my Linksys router with DD-WRT and added a startup command to login automatically. That method wasn't as effective as I desired. Its described here.

Reliance Broadband's Web Login

I thought of writing a script and adding it as a cron job to DD-WRT. The script would ping a known good server like www.google.com regularly and if the ping failed, it would login by passing the username and password via URL using wget. This was a good idea, I wrote up the script and tested it successfully on my xubuntu netbook but it didn't work on my Linksys WRT320N running DD-WRT. This was probably because cron seems to be broken on DD-WRT and I did not feel like spending time figuring our how to fix it.

Instead I switched to using a TP-LINK router, flashed it with OpenWRT (which is much easier to manipulated than DD-WRT), copied the script to it and added it to crontab for execution on every minute.

Here are the steps:

  1. Get a TP-LINK router (TP-LINK routers agree well with OpenWRT) and flash it with OpenWRT. To know how to get that done, refer to ONLY the steps outlined under the heading "Flashing the router with OpenWRT" in the post here.
  2. Create a text file on your computer and copy the following lines to it. Save it as login.sh If you are using a Windows PC, make sure to take care of Line Endings. Also, replace "1234567890" with your own username and "reset123" with your own password.
  3.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    # Send two Ping request packets and 4 seconds timeout
    return_value=$(ping -c 2 -W 4 www.google.com)
    return_value=$?
    # Return code for ping are taken from
    # ./OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/include/sysexits.h
     
        case $return_value in
            0)  #Ping reply received
                logger "Ping result: ONLINE"
                ;;
            1)  #Ping sent but reply was not received
                logger "Ping result: OFFLINE (Ping reply not received), Logging into Reliance..."
                wget 'http://reliancebroadband.co.in/reliance/startportal_isg.do?userId=12345678790&password=reset123&action=doLoginSubmit' -O /dev/null
                ;;
            *)  #Error
                logger "Ping result: OFFLINE (ping return code: $return_value), Logging into Reliance..."
                wget 'http://reliancebroadband.co.in/reliance/startportal_isg.do?userId=12345678790&password=reset123&action=doLoginSubmit' -O /dev/null
                ;;
        esac
    
  4. Copy the file login.sh to /root on the router. On a Windows PC, use WinSCP to do this. On a Linux PC use the command scp login.sh root@10.10.10.10:/root/login.sh to copy the file to the router, replacing 10.10.10.10 with the IP address of your router - Linux will as you for the router password before copying the file.
  5. Access the router's OpenWRT Web GUI and navigate to System>Scheduled Tasks and add the line * * * * * /root/login.sh to the text box. Click Apply and reboot the router.

    Adding the script as a cron job to crontab in OpenWRT
Once rebooted, the router will execute the script every 60 seconds. The script will check for connectivity and login if required. You can look up the System Log of the router to make sure the script is running.

System Log shows that the script is being run every minute successfully

Comments

  1. Hey Anurag,
    We met at the Pune Hackerspace the day your had demoed the stuff around the weather station and the twitter bulb.
    I am having serious trouble using Reliance Broadband with any router.
    Do you have like a how to on configuring the router for Reliance Connection?

    ReplyDelete
  2. WILL IT WORK WITH TPLINK WR740N VER 4

    ReplyDelete
  3. for me it is not working in wr740 n ver 4.i copied ur script to root and added crontab the task is running but it but the script is not ruuning, i have added wget to startup im able to loging by rebooting , but script is not running throough scheduled task, pls help me yaar

    ReplyDelete
  4. Thanks it is working now, wat i did is copied the script to bin folder and execution permission added working fine

    ReplyDelete
  5. # Send two Ping request packets and 4 seconds timeout
    return_value=$(ping -c 2 -W 4 8.8.8.8)
    return_value=$?
    # Return code for ping are taken from
    # ./OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/include/sysexits.h

    case $return_value in
    0) #Ping reply received
    logger "Ping result: ONLINE"
    ;;
    1) #Ping sent but reply was not received
    logger "Ping result: OFFLINE (Ping reply not received), Logging into Reliance..."
    wget 'http://reliancebroadband.co.in/reliance/startportal_isg.do?userId=12345678&password=12345&action=doLoginSubmit' -O /dev/null
    ;;
    *) #Error
    logger "Ping result: OFFLINE (ping return code: $return_value), Logging into Reliance..."
    wget 'http://reliancebroadband.co.in/reliance/startportal_isg.do?userId=12345678&password=12345&action=doLoginSubmit' -O /dev/null
    ;;
    esac

    ReplyDelete
  6. very good bro ! thanks in advanced

    please tell me curl command instead of wget
    I have loadbalancer on my router which supports only curl

    ReplyDelete
  7. I think the following should simply work:

    curl 'http://reliancebroadband.co.in/reliance/startportal_isg.do?userId=12345678790&password=reset123&action=doLoginSubmit'

    ReplyDelete

Post a Comment