-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnjuptNet.py
104 lines (88 loc) · 3.18 KB
/
njuptNet.py
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
94
95
96
97
98
99
100
101
102
103
104
import re
from urllib.parse import parse_qs, urlsplit
import requests
def getURL():
try:
response = requests.get("http://6.6.6.6/", timeout=3)
if response.url == "http://6.6.6.6/":
content = response.text
url = re.search("location.href=\\\"(http://.*)\\\"", content)
else:
redirectURL = response.url
url = re.search("(http://.*)", redirectURL)
except requests.exceptions.ConnectTimeout:
print("已登陆~请勿重复登录")
exit(0)
else:
return url.group(1)
def getConfig(url):
param = urlsplit(url).query
return parse_qs(param)
headers = {
'Connection': 'keep-alive',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'Origin': 'http://p.njupt.edu.cn',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
}
def getDataParams(cfg: dict, account: dict):
params = (
('c', 'ACSetting'),
('a', 'Login'),
('protocol', 'http:'),
('hostname', 'p.njupt.edu.cn'),
('iTermType', '1'),
('wlanuserip', cfg.get("wlanuserip")),
('wlanacip', cfg.get("wlanacip")),
('wlanacip', ''),
('wlanacname', cfg.get("wlanacname")),
('mac', '00-00-00-00-00-00'),
('ip', cfg.get("wlanuserip")),
('enAdvert', '0'),
('queryACIP', '0'),
('loginMethod', '1'),
)
data = {
'DDDDD': ',0,{username}'.format(username=account.get('user')),
# 'DDDDD': ',0,{username}@cmcc'.format(username=account.get('user')),
'upass': '{password}'.format(password=account.get('pwd')),
'R1': '0',
'R2': '0',
'R3': '0',
'R6': '0',
'para': '00',
'0MKKey': '123456',
'buttonClicked': '',
'redirect_url': '',
'err_flag': '',
'username': '',
'password': '',
'user': '',
'cmd': '',
'Login': '',
'v6ip': ''
}
return data, params
def Login(account: dict):
url = getURL()
cfg = getConfig(url)
data, params = getDataParams(cfg, account)
response = requests.post('http://p.njupt.edu.cn:801/eportal/', headers=headers, params=params, data=data)
if ( response.status_code == 200):
html = response.text
if re.search("认证成功页", html): # 实际上可以根据返回的url判断 2.html为失败, 3.html为成功
print("登录成功~")
else:
print("登录失败~密码错误~")
else:
print("登录失败, Unknown Error")
if __name__ == "__main__":
user = input("请输入账号(校园卡号):") # NJUPT直接输入卡号即可, 电信加后缀@njxy , 移动加后缀@cmcc
pwd = input("请输入密码(默认身份证后6位):")
account = {'user': user, 'pwd': pwd}
Login(account)