Tblogger

tikona.py

Jan 1st, 2016
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import mechanize
  5. import time
  6. from optparse import OptionParser
  7. import getpass
  8.  
  9. def Login(username,password):
  10.     print ">>> trying to connect.."
  11.     br = mechanize.Browser()
  12.     response  = br.open('https://login.tikona.in')
  13.     print ">>> ok"
  14.     print ">>> " + br.title()
  15.     #print response.geturl()
  16.     #print ">>>"
  17.     print ">>> redirecting to login.do"
  18.     br.select_form(nr=0)
  19.     br.form.action = 'https://login.tikona.in/userportal/login.do?requesturi=http%3A%2F%2F1.254.254.254%2F&act=null'
  20.     br.form.method = 'POST'
  21.     print ">>> submitting.."
  22.     response = br.submit()
  23.     print ">>> got response"
  24.     br.select_form(name="form1")
  25.     br["username"] = username
  26.     br["password"] = password
  27.     br.find_control(name="type").value = ["2"]
  28.     br.form.method="POST"
  29.     print ">>> proceeding to login.."
  30.     br.form.action="https://login.tikona.in/userportal/newlogin.do?phone=0"
  31.     print ">>> loggin in..."
  32.     print ">>> ok "
  33.     print ">>> " + br.title()
  34.     response = br.submit()
  35.     #response.get_data()
  36.     print ""
  37.     print 50 * "*"
  38.     print ""
  39.     print response.info()
  40.     print 50 * "*"
  41.     print ""
  42.     #print response.read()
  43.  
  44. def Logout():
  45.     print "Logging out.."
  46.     br = mechanize.Browser()
  47.     response = br.open('https://login.tikona.in/userportal/logout.do?svccat=1')
  48.     print response.geturl()
  49.     print response.info()
  50.     print response.read()
  51. def main():
  52.     parser = OptionParser()
  53.     usage = "Usage: %prog -u <username>"
  54.     parser = OptionParser(usage=usage, version="%prog 1.0")
  55.     parser.add_option("-u", "--username",  action="store", type="string",dest="user",  help="Username to login")
  56.     (options, args) = parser.parse_args()
  57.     if options.user:
  58.     password = getpass.getpass()
  59.         Login(options.user,password)
  60.     else:
  61.        print "Fatal: Required arguments are missing!"
  62.        print "Use: -h / --help to get help."
  63.  
  64. if __name__ == "__main__":
  65.    main()
Add Comment
Please, Sign In to add comment