/ 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.
Expand |
Embed | Plain Text
''' Syntax 1: "python gsulogin.py <username> <password> [remove old login]" Example 1: "python gsulogin.py js87235 mypassword" And then if you see that you have too many active users: Example 1b: "python gsulogin.py js87235 mypassword yes" ########################################################################### Syntax 2: "python gsulogin.py logout <user_key> NOTE: Your user_key will be printed out when you use this script to login Example 2: "python gsulogin.py logout 141.165.34.45_CUX614P30KDGNBAT" ''' import sys, getpass, urllib, re, time separator = "-----------------------------" print(separator + "\n Georgia Southern Network Login\n" + separator) if len(sys.argv) >= 3: #if logging out, just send logout url if (sys.argv[1] == "logout"): test = urllib.urlopen('https://smrtsrv2.georgiasouthern.edu/auth/perfigo_logout.jsp', 'user_key=' + sys.argv[2] ) print test.read() sys.exit() username = sys.argv[1] password = sys.argv[2] if len(sys.argv) > 3: removeOld = '1' print "removing old..." else: removeOld = '0' else: username = raw_input("Username: ") password = getpass.getpass() sometext = raw_input("Enter 'y' if you want to remove old login: "); if (sometext == 'Y'): removeOld = '1' else: removeOld = '0' #put it inside a function so multiple tries can be done #for autorunning, when system is just started up and not connected to internet yet tries = 0; def tryLogin(tries): tries = tries + 1 if (tries > 4): return 0 try: print "\nGetting userip from test run:" test = urllib.urlopen('https://smrtsrv2.georgiasouthern.edu/auth/perfigo_cm_validate.jsp') jane = test.read() pattern = re.compile('userip[^1-9]*([1-9.]*)') userip = pattern.search(jane).groups()[0] print separator + "\nYour CAA IP: " + userip + "\n" + separator print "\nAttempting to login..." data = urllib.urlopen('https://smrtsrv2.georgiasouthern.edu/auth/perfigo_cm_validate.jsp', 'reqFrom=perfigo_login.jsp' + '&provider=Student' + '&username=' + username + '&password=' + password + '&remove_old=' + removeOld + '&userip=' + userip + '&uri=http://www.google.com/' + '&cm=ws32vklm') print separator bob = data.read() if (re.search("Too many users", bob)): 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" elif (re.search("Invalid Clean Access Server", bob)): print "Invalid Clean Access Server (wtf is this?)" elif (re.search("Invalid username or password", bob)): print "Invalid username or password" elif (re.search("successfully logged on the network", bob)): print "You have been successfully logged into network." patter = re.compile('userkey[^1-9]*([^"]*)') print separator + "\nYour user_key is: " + patter.search(bob).groups()[0] + "\n"+separator else: print bob + "\n\n ERROR, unknown response, printed out the whole HTML above. Have fun reading through it." except IOError, e: print "IOError:", e, "\n", seperator print "Waiting 5 seconds and trying again..." time.sleep(5) tryLogin(tries) tryLogin(tries)
You need to login to post a comment.
