Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/home/sahil/anaconda3/bin/python3
- """
- A simple python script to automate IIT Mandi Gateway Authentication
- Author : Abhishek Pandey
- """
- from __future__ import print_function
- import getpass
- import signal
- import time
- import requests
- def main():
- """
- This function does pretty much everything.
- """
- ans = -1
- client = requests.session()
- gateways = ['stgw.iitmandi.ac.in/ug', 'gateway.iitmandi.ac.in/facstaff']
- auths = ['https://' + url + '/authenticate.php' for url in gateways]
- logouts = ['http://' + url + '/logout.php' for url in gateways]
- success_urls = ['http://' + url + '/success.php' for url in gateways]
- print("Please Choose your proxy server")
- for i, auth in enumerate(auths):
- print("[{}] {}".format(i + 1, auth))
- ans = input().strip()
- if ans not in ('1', '2'):
- print("Only 1 or 2 accepted as answers")
- return
- ans = int(ans) - 1
- auth = auths[ans]
- def logout(signal, frame):
- """
- SIGINT handler. Is run on Ctrl-C or kill by User
- Logs out the user.
- """
- print("Logging Out")
- if ans == -1:
- return
- resp = client.get(logouts[ans])
- if "Thankyou" in resp.text:
- print ("Logged out successfully!")
- exit(0)
- else:
- print ("Unable to logout!")
- signal.signal(signal.SIGINT, logout)
- print("Username: ")
- user = input()
- passwd = getpass.getpass()
- resp = client.post(auth, dict(username=user, password=passwd, url=""))
- email = "{}@students.iitmandi.ac.in".format(user)
- if email in resp.text:
- print("Login Successful")
- else:
- print("Login Failed. Please try again")
- return
- while True:
- time.sleep(20 * 60)
- client.get(success_urls[ans])
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment