Advertisement
Sushubh

Reliance Broadband Auto Login Script

Dec 22nd, 2014
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.93 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. """
  4.    Automatic login and keep alive for Reliance Broadband connections
  5.    This program automatically logs in to your Reliance Broadband connection
  6.    and keeps the session alive so that you don't have to login manually
  7.    Copyright (C) 2014 Vedant Lath, vedant@lath.in
  8.  
  9.    This program is free software: you can redistribute it and/or modify
  10.    it under the terms of the GNU Affero General Public License as
  11.    published by the Free Software Foundation, version 3 of the License.
  12.  
  13.    This program is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU Affero General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU Affero General Public License
  19.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20. """
  21.  
  22. import urllib.request, urllib.parse, urllib.error
  23. import datetime
  24. import sys
  25. import time
  26.  
  27. # enter your Reliance Broadband username and password here
  28. username = "USERNAME"
  29. password = "PASSWORD"
  30.  
  31. # check if we are logged out every 10 seconds
  32. check_interval = 10
  33.  
  34. # don't edit anything below this line
  35. enable_logging = True
  36. loginurl = "http://reliancebroadband.co.in/reliance/startportal_isg.do"
  37. statusurl = "http://reliancebroadband.co.in/reliance/startportal_isg.do"
  38. #statusurl = "http://reliancebroadband.co.in/reliance/sessionStatus.do"
  39.  
  40. f = None
  41. if enable_logging:
  42.     f = open('log', 'a')
  43.  
  44. def log(message):
  45.     if (not enable_logging):
  46.         return
  47.     f.write(str(datetime.datetime.now()) + ": " + message + "\n")
  48.  
  49. def log_response(response, responsestring):
  50.     if (not enable_logging):
  51.         return
  52.  
  53.     responseurl = response.geturl()
  54.     responsecode = response.getcode()
  55.     responseinfo = response.info()
  56.     f.write(str(datetime.datetime.now()) + ": Response received: " + str(responseurl) + " " + str(responsecode) + "\n" + str(responseinfo) + "\n\n" + responsestring + "\n")
  57.     return responsestring
  58.  
  59. def login():
  60.     postdata = urllib.parse.urlencode({'action': 'doLoginSubmit', 'userId': username, 'password': password})
  61.     postdata = postdata.encode('utf-8')
  62.  
  63.     log("Requesting login with userId " + username + " and password " + password)
  64.  
  65.     responsestring = ""
  66.     try:
  67.         response = urllib.request.urlopen(loginurl, data=postdata, timeout=2)
  68.         responsestring = str(response.read(), 'utf-8')
  69.         log_response(response, responsestring)
  70.         if (responsestring.find("logout") > -1):
  71.             log("login request successful")
  72.             return True
  73.         else:
  74.             log("login request failed")
  75.             return False
  76.     except urllib.error.URLError as strerror:
  77.         log("login request failed, " + str(strerror))
  78. #    except:
  79. #        log("unexpected error, " + sys.exc_info().__str__())
  80.  
  81. def status():
  82.     log("Requesting status")
  83.  
  84.     responsestring = ""
  85.     try:
  86.         response = urllib.request.urlopen(statusurl, timeout=2)
  87.         responsestring = str(response.read(), 'utf-8')
  88.         log_response(response, responsestring)
  89.         if (responsestring.find("logout") > -1):
  90.             log("we are not logged in")
  91.             return True
  92.         else:
  93.             log("we are logged in")
  94.             return False
  95.     except urllib.error.URLError as strerror:
  96.         log("login request failed, " + str(strerror))
  97. #    except:
  98. #        log("unexpected error, " + sys.exc_info().__str__())
  99.  
  100. log("script started")
  101. while True:
  102.     print("getting session status")
  103.     is_logged_in = status()
  104.     if (is_logged_in is True):
  105.         print("Woohoo!")
  106.     else:
  107.         print("Boohoo!")
  108.  
  109.     while (not is_logged_in):
  110.         is_logged_in = login()
  111.         if (is_logged_in is True):
  112.             print("Shukar Hai!")
  113.         else:
  114.             print("Beda Garak Haiยก")
  115.         time.sleep(2)
  116.  
  117.     time.sleep(check_interval)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement