Skip to content

Instantly share code, notes, and snippets.

@scientificRat
Created October 17, 2018 11:12
Show Gist options
  • Save scientificRat/04eb450f4755650ccf3214631cdd32c0 to your computer and use it in GitHub Desktop.
Save scientificRat/04eb450f4755650ccf3214631cdd32c0 to your computer and use it in GitHub Desktop.
清华大学校园网命令行登陆/退出脚本
import requests
import argparse
import hashlib
def login(username, password):
password = '{MD5_HEX}' + hashlib.md5(password.encode('utf-8')).hexdigest()
r = requests.post('http://net.tsinghua.edu.cn/do_login.php',
data={'action': 'login', 'username': username, 'password': password, 'ac_id': 1})
print(r.text)
def logout():
r = requests.post('http://net.tsinghua.edu.cn/do_login.php',
data={'action': 'logout'})
print(r.text)
def main():
parser = argparse.ArgumentParser(description='Connection tool for Tsinghua')
parser.add_argument('action', help='login or logout')
parser.add_argument('--username', '-u')
parser.add_argument('--password', '-p')
args = parser.parse_args()
if args.action == 'login':
if args.username is None or len(args.username) == 0:
print('username cannot be empty')
return
if args.password is None or len(args.password) == 0:
print('password cannot be empty')
return
login(args.username, args.password)
elif args.action == 'logout':
logout()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment