This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsrun4k.py
119 lines (114 loc) · 2.24 KB
/
srun4k.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
import password
import requests
class pySrun4kError(Exception):
def __init__(self,reason):
Exception.__init__(self)
self.reason = reason
def do_login(username,pwd,mbytes=0,minutes=0):
pwd = password.encrypt(pwd)
payload = {
'action':'login',
'username':username,
'password':pwd,
'drop':0,
'pop':0,
'type':2,
'n':117,
'mbytes':0,
'minutes':0,
'ac_id':1
}
header = {
'user-agent':'pySrun4k'
}
r = requests.post("http://10.0.0.55/cgi-bin/srun_portal",data=payload,headers=header)
if ('login_error' in r.text):
ret = {
'success':False,
'code':int(r.text[13:17]),
'reason':r.text[19:]
}
return ret;
elif ('login_ok' in r.text):
ret = {
'success':True,
'data':r.text.split(',')[1:]
}
return ret;
else:
raise pySrun4kError(r.text)
def check_online():
header = {
'user-agent':'pySrun4k'
}
r = requests.get("http://10.0.0.55/cgi-bin/rad_user_info",headers=header)
if ('not_online' in r.text):
ret = {
'online':False
}
return ret
else:
raw = r.text.split(',')
ret = {
'online':True,
'username':raw[0],
'login_time':raw[1],
'now_time':raw[2],
'used_bytes':raw[6],
'used_second':raw[7],
'ip':raw[8],
'balance':raw[11],
'auth_server_version':raw[21]
}
return ret
def do_logout(username):
header = {
'user-agent':'pySrun4k'
}
payload = {
'action':'logout',
'ac_id':1,
'username':username, #这参数好像没啥用,不过好像不传又不行.
'type':2
}
r = requests.post('http://10.0.0.55/cgi-bin/srun_portal',data=payload,headers=header)
if ('logout_ok' in r.text):
ret = {
'success':True,
}
return ret;
elif ('login_error' in r.text):
ret = {
'success':False,
'reason':r.text.split('#')[1]
}
return ret
else:
raise pySrun4kError(r.text)
def force_logout(username,pwd):
payload = {
'action':'logout',
'username':username,
'password':pwd,
'drop':0,
'type':1,
'n':117,
'ac_id':1
}
header = {
'user-agent':'pySrun4k'
}
r = requests.post('http://10.0.0.55/cgi-bin/srun_portal',data=payload,headers=header)
if ('logout_ok' in r.text):
ret = {
'success':True
}
return ret
elif ('login_error' in r.text):
ret = {
'success':False,
'reason':r.text.split('#')[1]
}
return ret
else:
raise pySrun4kError(r.text)