Posted By

jakswa on 02/05/09


Tagged

login web GSU


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mustapha


GSU Login


 / Published in: Python
 

URL: http://ubuntune.blogspot.com

This script is currently undergoing test, and is targeted towards Linux users (afaik, Windows/Mac users have to deal with the installed Clean Access Agent). This script's purpose to automate the login of GSU's computer network using python, instead of their web interface.

I stole the basis for this script from http://snipplr.com/view/3587/georgia-tech-lawn-login-script/

My thanks to that guy.

  1. '''
  2. Syntax 1: "python gsulogin.py <username> <password> [remove old login]"
  3.  
  4. Example 1: "python gsulogin.py js87235 mypassword"
  5. And then if you see that you have too many active users:
  6. Example 1b: "python gsulogin.py js87235 mypassword yes"
  7.  
  8. ###########################################################################
  9.  
  10. Syntax 2: "python gsulogin.py logout <user_key>
  11. NOTE: Your user_key will be printed out when you use this script to login
  12.  
  13. Example 2: "python gsulogin.py logout 141.165.34.45_CUX614P30KDGNBAT"
  14.  
  15. '''
  16.  
  17. import sys, getpass, urllib, re, time
  18.  
  19. separator = "-----------------------------"
  20. print(separator +
  21. "\n Georgia Southern Network Login\n" +
  22. separator)
  23.  
  24. if len(sys.argv) >= 3:
  25. #if logging out, just send logout url
  26. if (sys.argv[1] == "logout"):
  27. test = urllib.urlopen('https://smrtsrv2.georgiasouthern.edu/auth/perfigo_logout.jsp',
  28. 'user_key=' + sys.argv[2] )
  29. print test.read()
  30. sys.exit()
  31.  
  32. username = sys.argv[1]
  33. password = sys.argv[2]
  34. if len(sys.argv) > 3:
  35. removeOld = '1'
  36. print "removing old..."
  37. else:
  38. removeOld = '0'
  39. else:
  40. username = raw_input("Username: ")
  41. password = getpass.getpass()
  42. sometext = raw_input("Enter 'y' if you want to remove old login: ");
  43. if (sometext == 'Y'):
  44. removeOld = '1'
  45. else:
  46. removeOld = '0'
  47.  
  48. #put it inside a function so multiple tries can be done
  49. #for autorunning, when system is just started up and not connected to internet yet
  50. tries = 0;
  51. def tryLogin(tries):
  52. tries = tries + 1
  53. if (tries > 4):
  54. return 0
  55.  
  56. try:
  57.  
  58. print "\nGetting userip from test run:"
  59. test = urllib.urlopen('https://smrtsrv2.georgiasouthern.edu/auth/perfigo_cm_validate.jsp')
  60. jane = test.read()
  61. pattern = re.compile('userip[^1-9]*([1-9.]*)')
  62. userip = pattern.search(jane).groups()[0]
  63. print separator + "\nYour CAA IP: " + userip + "\n" + separator
  64.  
  65. print "\nAttempting to login..."
  66. data = urllib.urlopen('https://smrtsrv2.georgiasouthern.edu/auth/perfigo_cm_validate.jsp',
  67. 'reqFrom=perfigo_login.jsp' +
  68. '&provider=Student' +
  69. '&username=' + username +
  70. '&password=' + password +
  71. '&remove_old=' + removeOld +
  72. '&userip=' + userip +
  73. '&uri=http://www.google.com/' +
  74. '&cm=ws32vklm')
  75. print separator
  76. bob = data.read()
  77. if (re.search("Too many users", bob)):
  78. print "Too many users on account, use the syntax: \n\n python login.py [user] [pass] [anything you want]\n\nto attempt to remove an old user account.\n"
  79. elif (re.search("Invalid Clean Access Server", bob)):
  80. print "Invalid Clean Access Server (wtf is this?)"
  81. elif (re.search("Invalid username or password", bob)):
  82. print "Invalid username or password"
  83. elif (re.search("successfully logged on the network", bob)):
  84. print "You have been successfully logged into network."
  85. patter = re.compile('userkey[^1-9]*([^"]*)')
  86. print separator + "\nYour user_key is: " + patter.search(bob).groups()[0] + "\n"+separator
  87. else:
  88. print bob + "\n\n ERROR, unknown response, printed out the whole HTML above. Have fun reading through it."
  89.  
  90. except IOError, e:
  91. print "IOError:", e, "\n", seperator
  92. print "Waiting 5 seconds and trying again..."
  93. time.sleep(5)
  94. tryLogin(tries)
  95.  
  96. tryLogin(tries)

Report this snippet  

You need to login to post a comment.