-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path校园网.py
157 lines (146 loc) · 6.02 KB
/
校园网.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import requests
import json
import socket
import time
import re
import sys
import hashlib
# 校园网账号
userid = "账号"
# 校园网密码
passwd = "密码"
# 校园网管理后台登录域名
xywhost = "http://11.11.11.11"
# 校园网登录链接的wlanacname
wlanacname = "XXXX"
hostsname = socket.gethostname()
loginmsg = "test"
# 主程序
def main():
# try:
global passmd5
passmd5 = get_md5(passwd)
print("*******程序开始运行*******","\n主机名:",hostsname,"\n你的IP是:", ip())
print("3秒后开始登录操作")
time.sleep(2)
logout()
login()
# except:
print("")
exit
# 获取内网IP
def ip():
global ip
global passmd5
url = "http://1.1.1.1"
x = requests
r = x.get(url, allow_redirects=False)
rtext = r.text
result = re.search(r"\d{1,3}.\d{2,3}.\d{1,3}.\d{1,3}",str(rtext))
ip = result.group()
return ip
def login():
global ip
# 登录操作
x2 = requests
x = requests.session()
x.get(xywhost)
quickAuthShare = x.get(xywhost + "/quickAuthShare.do?wlanacip=&wlanacname=" + wlanacname + "&userId=" + userid + "&passwd=" + passwd + "&mac=&wlanuserip=" + ip)
data = json.loads(quickAuthShare.text)
loginmsg = data["message"]
# 获取验证码
r = x.post(xywhost + "/self/tologin.do")
data = json.loads(r.text)
verifyCode = data["data"]["verifyCode"]
print("验证码:",verifyCode)
# 登录操作获取cookie
headers={
'Connection': 'keep-alive',
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json;charset=UTF-8',
'Origin': xywhost,
'Referer': xywhost + '/self/index.html',
'Accept-Encoding': 'gzip,deflate',
'Accept-Language': 'zh-CN,zh;q=0.9'
}
data = '{"accountId":"' + userid + '","password":"' + passmd5 + '","verifyCode":"'
r2 = x.post(url=xywhost + "/self/login.do?",headers=headers,data=data+verifyCode+"\"}")
data = json.loads(r2.text)
status = data["errmsg"]
print("登录:",status)
print(loginmsg)
# 数据变量
num = 0
times = 0
while True:
try:
# 获取在线清单和设备ID
data2 = '{"accountId":"' + userid + '"}'
r3 = x.post(url=xywhost +"/self/getonline.do?",headers=headers,data=data2)
data = json.loads(r3.text)
online = data["rows"]
if('billingId'in r3.text):
print("**********设备在线*******")
online = data["rows"][0]["billingId"]
serverIp = data["rows"][0]["serverIp"]
ip = data["rows"][0]["accountIp"]
print("在线设备:",online,"\n设备IP:",ip,)
# 下线设备
data3 = '{"accountId":"' +userid + '","accountIp":"'+ ip +'","billingId":"'+ online +'","serverIp":"' + serverIp + '"}'
r4 = x.post(url=xywhost+"/self/kickonline.do?",headers=headers,data=data3)
quickAuthShare = x.get(xywhost + "/quickAuthShare.do?wlanacip=&wlanacname="+ wlanacname + "&userId=" + userid + "&passwd=" + passwd + "&mac=&wlanuserip=" + ip)
data = json.loads(r4.text)
status = data["errmsg"]
times += 1
print("设备" + status + ",拨号" + str(times) + "次")
num = 0
time.sleep(1)
quickAuthShare = x.get(xywhost + "/quickAuthShare.do?wlanacip=&wlanacname="+ wlanacname + "&userId=" + userid + "&passwd=" + passwd + "&mac=&wlanuserip=" + ip)
data = json.loads(quickAuthShare.text)
loginmsg = data["message"]
print(loginmsg)
else:
num += 1
if ( num>5 ):
headers2={
'Cache-Control': 'no-cache'
}
r5 = x2.get("http://h5.analytics.126.net/news/c", headers=headers2 , allow_redirects=False)
if( 'ok'in r5.text ):
print("登录状态:联网成功!")
print("登录状态:联网成功!")
print("登录状态:联网成功!")
input("\n\n")
exit()
else:
print("登录状态:登录失败!")
logout()
login()
else:
pass
time.sleep(1)
except:
print("")
break
def logout():
# 断网操作
x = requests.session()
r = x.get(xywhost+"/quickAuthShare.do?wlanacip=&wlanacname="+ wlanacname +"&userId=" + userid + "&passwd=" + passwd + "&mac=&wlanuserip=" + ip)
data = json.loads(r.text)
distoken = data["distoken"]
print("distoken:",distoken)
time.sleep(2)
r2 = x.get(xywhost+"/httpservice/appoffline.do?wlanacip=&wlanacname="+ wlanacname +"&userId=" + userid + "&passwd=" + passwd + "&mac=&wlanuserip=" + ip + "&distoken="+ distoken)
data = json.loads(r2.text)
message = data["message"]
print("下线状态:",message)
quickAuthShare = x.get(xywhost + "/quickAuthShare.do?wlanacip=&wlanacname="+ wlanacname +"&userId=" + userid + "&passwd=" + passwd + "&mac=&wlanuserip=" + ip)
def get_md5(v):
import hashlib
# Message Digest Algorithm MD5(中文名为消息摘要算法第五版)为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护
md5 = hashlib.md5() #md5对象,md5不能反解,但是加密是固定的,就是关系是一一对应,所以有缺陷,可以被对撞出来
## update需要一个bytes格式参数
md5.update(v.encode('utf-8')) #要对哪个字符串进行加密,就放这里
value = md5.hexdigest() #拿到加密字符串
return value
main();