HFUT 校园网自动登录脚本
学校的校园网每次开机都需要重新登录才能使用,很麻烦。这个脚本可以实现自动登录校园网,只需将其加入到开机自启动中即可。
这是自动登录脚本,无法用于破解校园网,使用的前提是已经有可用的校园网账号!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
import re
import requests
USERNAME = '2017000000' PASSWORD = 'your_password'
test_urls = ['http://koolshare.cn/portal.php', 'http://www.sosoapi.com/']
count_success_url = 0 count_fail_url = 0
s = requests.Session() for test_url in test_urls: print('url: ', test_url) for i in range(3): cdn_r = s.get(test_url, allow_redirects=False) if cdn_r.text.find('top.self.location.href') != -1: count_fail_url = count_fail_url + 1 print('try {0}, failed.'.format(i)) else: count_success_url = count_success_url + 1 print('try {0}, succeed.'.format(i)) print('success: ', count_success_url, ', fail_url: ', count_fail_url)
if count_success_url > count_fail_url: print('您已经登录!') exit()
print('正在获取初始化页面地址: ') cdn_r = s.get('http://cdn.bootcss.com/jquery/3.4.1/jquery.min.js', allow_redirects=False) re_match = re.search('http\S*\'', cdn_r.text) if re_match is None: print('获取初始化地址失败,可能已经登录!') exit() session_url = re_match.group()[:-1] print(session_url)
print('正在建立 Session: ') session = s.get(session_url)
print('开始登录') r = s.post('http://210.45.240.245/post.php', data={'username': USERNAME, 'password': PASSWORD, '0MKKey': '%B5%C7+%C2%BC'}) print('登录成功')
|