From 7a9e0dcca035d3649ba6814aa7918bd9f2c31e1c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 31 Oct 2020 15:40:36 +0800 Subject: [PATCH] initial --- autologin.py | 27 ++++++++++++++++++++++++ login.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 autologin.py create mode 100644 login.py diff --git a/autologin.py b/autologin.py new file mode 100644 index 0000000..11463f5 --- /dev/null +++ b/autologin.py @@ -0,0 +1,27 @@ +import json +import re +from urllib import request +from tkinter import messagebox + +filename = "info.json" +with open(filename, "r") as f: + info = json.load(f) + account = info["name"] + password = info["password"] +captiveReturnCode = request.urlopen("http://www.google.cn/generate_204").getcode() +if captiveReturnCode == 204: + messagebox.showinfo(title="恭喜", message="你已连接网络,无需登录") +else: + loginPageURL = request.urlopen("http://www.google.cn/generate_204").read().decode() + loginPageURL = re.search(r"'(.*)'", loginPageURL).group(1) + loginURL = loginPageURL.split("?")[0].replace("index.jsp", "InterFace.do?method=login") + queryString = loginPageURL.split("?")[1] + data = "userId=" + account + "&password=" + password +"&service=&queryString=" + queryString + "&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=false" + postdata = data.encode() + req = request.Request(loginURL, data=postdata) + resp = request.urlopen(req).read().decode() + resp = json.loads(resp)["message"] + if resp == "": + messagebox.showinfo(title="提示", message="登录成功") + else: + messagebox.showinfo(title="提示", message=resp) \ No newline at end of file diff --git a/login.py b/login.py new file mode 100644 index 0000000..28afeee --- /dev/null +++ b/login.py @@ -0,0 +1,58 @@ +import tkinter +from tkinter import messagebox +import json +import re +from urllib import request + +def login(): + with open(filename, "w") as f: + info = { + "name": eN.get(), + "password": eP.get() + } + json.dump(info, f) + account = eN.get() + password = eP.get() + captiveReturnCode = request.urlopen("http://www.google.cn/generate_204").getcode() + if captiveReturnCode == 204: + messagebox.showinfo(title="恭喜", message="你已连接网络,无需登录") + else: + loginPageURL = request.urlopen("http://www.google.cn/generate_204").read().decode() + loginPageURL = re.search(r"'(.*)'", loginPageURL).group(1) + loginURL = loginPageURL.split("?")[0].replace("index.jsp", "InterFace.do?method=login") + queryString = loginPageURL.split("?")[1] + data = "userId=" + account + "&password=" + password +"&service=&queryString=" + queryString + "&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=false" + postdata = data.encode() + req = request.Request(loginURL, data=postdata) + resp = request.urlopen(req).read().decode() + resp = json.loads(resp)["message"] + if resp == "": + messagebox.showinfo(title="提示", message="登录成功") + else: + messagebox.showinfo(title="提示", message=resp) + +filename = "info.json" +root = tkinter.Tk() +root.geometry("500x300") +root.title("校园网登录器") +lN = tkinter.Label(root, text="账号") +lN.pack() +vN = tkinter.StringVar(root, value="") +eN = tkinter.Entry(root, textvariable=vN) +eN.pack() +lP = tkinter.Label(root, text="密码") +lP.pack() +vP = tkinter.StringVar(root, value="") +eP = tkinter.Entry(root, show="*", textvariable=vP) +eP.pack() +try: + with open(filename, "r") as f: + info = json.load(f) + vN.set(info["name"]) + vP.set(info["password"]) +except: + pass +lB = tkinter.Button(root, text="登录", command=login) +lB.pack() + +root.mainloop() \ No newline at end of file