Reliance Wireless broadband auto-login (and logout) script(s)

The old “curl” based method stopped working yesterday when Reliance got a new login page as well as a new backend. It seems Reliance is now also looking at Cookies during authentication. Here’s a little Python script that you can execute to automate the process.

If you don’t know what Python is, you better stick to browser based authentication 🙂

Needless to say, you can schedule this script as a cron/ launchd job to run periodically and keep you logged in. That’s how I use it, which is why the script doesn’t output anything to prevent unnecessary log “pollution”.

Login Script for Python 2.x

#!/usr/bin/env python
# encoding: utf-8
"""
Reliance Login Script for Python 2.x v1.0

Created by Kunal Dua on 2009-12-18
Reliance Wireless broadband auto-login (and logout) script(s)
This program is free software; you may redistribute it and/or modify it under the same terms as Python itself. """ import urllib2, urllib, cookielib username = '1111111111111111' #replace the text within quotes with your username password = 'password' #replace the text within quotes with your password jar = cookielib.FileCookieJar("cookies") opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) response = opener.open("http://10.239.89.15/reliance/startportal_isg.do") login_data = urllib.urlencode({'userId' : username, 'password' : password, 'action' : 'doLoginSubmit'}) resp = opener.open('http://10.239.89.15/reliance/login.do', login_data)

Update: Logout Script for Python 2.x

#!/usr/bin/env python
# encoding: utf-8
"""
Reliance Logout Script v1.0

Created by Kunal Dua on 2009-12-22
http://www.kunaldua.com/blog/?p=323

This program is free software; you may redistribute it and/or
modify it under the same terms as Python itself.
"""

import urllib2, cookielib

jar = cookielib.FileCookieJar("cookies")
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

response = opener.open("http://10.239.89.15/reliance/login.do", timeout=2)

resp = opener.open('http://10.239.89.15/reliance/logout.do')

Update: Login Script for Python 3.x

#!/usr/bin/env python
# encoding: utf-8
"""
Reliance Login Script for Python 3.0 v1.0

Created by Kunal Dua on 2009-12-30
http://www.kunaldua.com/blog/?p=323

This program is free software; you may redistribute it and/or
modify it under the same terms as Python itself.
"""

import urllib, http.cookiejar

username = '1111111111111111' #replace the text within quotes with your username
password = 'password'	#replace the text within quotes with your password

jar = http.cookiejar.FileCookieJar("cookies")
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar))

response = opener.open("http://10.239.89.15/reliance/startportal_isg.do")

login_data = urllib.parse.urlencode({'userId' : username, 'password' : password, 'action' : 'doLoginSubmit'})
resp = opener.open('http://10.239.89.15/reliance/login.do', login_data)

echo what you read with IFS

Sample this code for reading a file line by line:

#!/bin/ksh
while read LINE
do
    echo "$LINE"
done < $FILENAME

It works fine in most cases, where by most cases I mean your lines don't have any trailing spaces that you'd like to preserve. That's right, read reserves the right to kill the trailing (and leading) spaces from your lines. Sample this (from ksh man page):

The IFS parameter specifies a list of characters which are used to break a string up into several words; any characters from the set space, tab and newline that appear inthe IFS characters are called IFS white space. Sequences of one or more IFS white space characters, in combination with zero or one non IFS white space characters delimit a field. As a special case, leading and trailing IFS white space is stripped (i.e., no leading ortrailing emptyfield is created by it); leading or trailing non-IFS white space does create an empty field.Example: if IFS is set to `:',the sequence of characters `A:B::D' contains four fields: `A', `B', `' and `D'. Note that if the IFS parameter is set to the null string, no field splitting is done; if the parameter is unset, the default value of space, tab and newline is used.

So, the above code should be changed to this - just the one line added:

#!/bin/ksh
IFS=""
while read LINE
do
    echo "$LINE"
done < $FILENAME

Now the above code gives the byte-by-byte output of the file. Or does it?

Problem is, if the file does not have an empty line at the end you'll see that the last line never shows up in the output! So how do we fix this? The "old-fashioned" way - by adding an extra "echo $LINE" outside the loop.

Does it work fine now? Not quite. Now you'll see an extra empty line at the end of the output file. How do we fix that? Use "echo -n". The "-n" option tells echo not to print the trailing newline character.

So finally we have our code to read a file line by line, do something with that line and write a modified line - and preserve every single bit along the way. Here it is then:

#!/bin/ksh
IFS=""
while read -r LINE
do
    echo "$LINE"
done < $FILENAME
echo -n $LINE