python 登录wust wifi6
登录请关闭科学上网
import requests import time import re from encryption.srun_md5 import * from encryption.srun_sha1 import * from encryption.srun_base64 import * from encryption.srun_xencode import * import os import datetime header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36' } init_url = "http://59.68.177.183/" get_challenge_api = "http://59.68.177.183/cgi-bin/get_challenge" srun_portal_api = "http://59.68.177.183/cgi-bin/srun_portal" get_info_api = "http://59.68.177.183/cgi-bin/rad_user_info?callback=jQuery_47" n = '200' type = '1' ac_id = '7' enc = "srun_bx1" def test_bing_connection(): """Test internet connection to Bing's homepage. Returns: str: "Connected" if successful, "Error" otherwise. """ url = "https://www.bing.com" try: response = requests.get(url, timeout=5) if response.status_code == 200: return "Connected" else: return "Error" except requests.RequestException: return "Error" def get_connect_status(): result = test_bing_connection() if result == "Error": print("网络连接失败,检查是否科学上网......") os.environ['http_proxy'] = 'http://127.0.0.1:7890' os.environ['https_proxy'] = 'http://127.0.0.1:7890' result = test_bing_connection() del os.environ['http_proxy'] del os.environ['https_proxy'] if result=='Connected': return True else: return False def get_chksum(): chkstr = token + username chkstr += token + hmd5 chkstr += token + ac_id chkstr += token + ip chkstr += token + n chkstr += token + type chkstr += token + i return chkstr def get_info(): info_temp = {
"username": username, "password": password, "ip": ip, "acid": ac_id, "enc_ver": enc } i = re.sub("'", '"', str(info_temp)) i = re.sub(" ", '', i) return i def init_getip(): global ip init_res = requests.get(init_url, headers=header) print("初始化获取ip") ip = re.search('ip : "(.*?)"', init_res.text).group(1) print("ip:" + ip) def get_token(): # print("获取token") global token get_challenge_params = {
"callback": "jQuery_" + str(int(time.time() * 1000)), "username": username, "ip": ip, "_": int(time.time() * 1000), } get_challenge_res = requests.get(get_challenge_api, params=get_challenge_params, headers=header) token = re.search('"challenge":"(.*?)"', get_challenge_res.text).group(1) # print(get_challenge_res.text) print("token为:" + token) def do_complex_work(): global i, hmd5, chksum i = get_info() i = "{SRBX1}" + get_base64(get_xencode(i, token)) hmd5 = get_md5(password, token) chksum = get_sha1(get_chksum()) print("所有加密工作已完成") def login(): srun_portal_params = {
'callback': 'jQuery_' + str(int(time.time() * 1000)), 'action': 'login', 'username': username, 'password': '{MD5}' + hmd5, 'ac_id': ac_id, 'ip': ip, 'chksum': chksum, 'info': i, 'n': n, 'type': type, 'os': 'windows+10', 'name': 'windows', 'double_stack': '0', '_': int(time.time() * 1000) } # print(srun_portal_params) srun_portal_res = requests.get(srun_portal_api, params=srun_portal_params, headers=header) # print(srun_portal_res.text) if __name__ == '__main__': global username, password username = "" password = "" connect_status=get_connect_status() if connect_status: print('网络正常连接,无需登录') else: print('网络断开连接,正在登录') try: init_getip() get_token() do_complex_work() login() res = requests.get(get_info_api, headers=header) print("用户", username, '登陆成功!') except: current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') with open('error.txt', 'a+', encoding='utf8') as fp: fp.write(f'[{
current_time}] login failed\n') print('登录失败!')
讯享网
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/20349.html