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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| import requests import os import json import configparser import win32api import win32con
def readInfo(): fileName = "accinfo.ini" conf = configparser.ConfigParser() conf.read(fileName) if os.path.exists(fileName): user = conf.get('config', 'user') password = conf.get('config', 'password') if user == "" or password == "": win32api.MessageBox(0, "你想拿空气登录吗(\n例:\n[config]\nuser = 11451419198\npassword = 123456", "错误",win32con.MB_ICONERROR) os.system(os.getcwd()+"\\"+fileName) readInfo() else: print("登录账号: {}".format(user)) print("登录密码: {}".format(password)) print("请稍等......") connectWeb(user,password) else: print("配置文件错误或不存在") print("首次启动需要提供上网账号与密码") print("在运行目录 \"{}\" 生成 accinfo.ini".format(os.getcwd())) conf.add_section('config') conf.set('config', 'user', '') conf.set('config', 'password', '') with open(fileName, 'w') as fw: conf.write(fw) print("请在accinfo.ini中填写上网账号(user)与密码(password),保存并关闭") win32api.MessageBox(0, "首次启动需要提供上网账号与密码,请在accinfo.ini中填写上网账号(user)与密码(password),保存并关闭\n例:\n[config]\nuser = 11451419198\npassword = 123456", "提示",win32con.MB_ICONASTERISK) os.system(os.getcwd()+"\\"+fileName) readInfo()
def connectWeb(user,password): url = "http://1.1.1.1" try: res = requests.get(url,allow_redirects=False) location = res.headers["Location"] except BaseException as err: print("--------错误--------") print(str(err)) os.system("pause") else: print("重定向到{}".format(location)) login(user,password,location)
def login(user,password,location): ip = "223.99.141.139:9090" url = "http://{}/web/connect".format(ip) data = { "web-auth-user": user, "web-auth-password": password, "redirect-url": location } header = { "Accept": "*/*", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Content-Length": "219", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Cookie": "BIGipServersc-ltm-xywpt-portal3-pool=135926188.33315.0000", "Host": ip, "Origin": "http://{}".format(ip), "Referer": location, "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36", "X-Requested-With": "XMLHttpRequest" } res = requests.post(url,data,headers=header) print("回应代码: {}".format(res.status_code))
if res.status_code == 200: print("登录成功") os.system("pause") else: data = json.loads(res.text) print("错误代码: {}\n{}".format(data["error"],data["error_description"])) print("登录失败,请检查账号密码是否正确/是否被其它设备占用") os.system("pause")
if __name__ == '__main__': try: print("NetKeeper山东移动高校宽带一键登录") print("v1.1.0.210306") readInfo() except BaseException as err: print("--------错误--------") print(str(err)) os.system("pause")
|