import msvcrt import requests import time import json import os
if os.name == "nt": os.system("")
os.chdir(os.getenv('TMP'))
file_name = "user_account.json"
if not os.path.exists(file_name): account = input("Please input your account: ") password = input("Please input your password: ") res = { 'account': account, 'password': password } print(res) with open(file_name, "w+") as fp: fp.write(json.dumps(res))
else: with open(file_name, "r")as fp: res = json.loads(fp.read()) account = res['account'] password = res['password'] headers = { "X-Requested-With": "XMLHttpRequest", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", }
def do_encrypt_rc4(src:str, passwd:str)->str: i, j, a, b, c = 0, 0, 0, 0, 0 key, sbox = [], [] plen = len(passwd) size = len(src) output = ""
for i in range(256): key.append(ord(passwd[i % plen])) sbox.append(i) for i in range(256): j = (j + sbox[i] + key[i]) % 256 temp = sbox[i] sbox[i] = sbox[j] sbox[j] = temp for i in range(size): a = (a + 1) % 256 b = (b + sbox[a]) % 256 temp = sbox[a] sbox[a] = sbox[b] sbox[b] = temp c = (sbox[a] + sbox[b]) % 256 temp = ord(src[i]) ^ sbox[c] temp = str(hex(temp))[-2:] temp = temp.replace('x', '0') output += temp return output def auth_go(): url = "http://1.1.1.3/ac_portal/login.php" tag = int(time.time()*1000) pwd = do_encrypt_rc4(password, str(tag)) payload = f"opr=pwdLogin&userName={account}&pwd={pwd}&auth_tag={tag}&rememberPwd=1"
while True: try:
res = requests.post(url, data=payload, headers=headers) print(res) if res.status_code == 200 and res.text.find("true")>0: print(f"\033[7;32;47m{res.content.decode('utf-8')} \033[0m") else: print(f"\033[7;31;47m{res.content.decode('utf-8')} \033[0m") print("\033[7;31;47m", "Login fail! Make sure input true account info!", "\033[0m") os.remove(file_name) print("\033[7;36;47m", "Already clear account file.\n Restart EXE and input again.", "\033[0m") break except Exception as err: print("\033[7;31;47m","Login Error!\tMaybe you need link wifi first?" ,"\033[0m") print("\033[7;33;40m", err,"\033[0m") time.sleep(10) break
def ping_check(ip_or_host): cmd = "ping %s -n 1 " % ip_or_host a = os.popen(cmd) b = a.read().strip() if "100% 丢失" in b: return False return True
def main(): while True: res = ping_check("1.2.4.8") time.sleep(5) if not res: print("检测到网络断开,尝试认证网络!") auth_go() continue main()
|