-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.py
75 lines (57 loc) · 2.02 KB
/
global.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
#!/usr/bin/env python3
import urllib.request
import urllib.parse
import argparse
import json
import time
def checkStatus(url, username):
statusJson = urllib.request.urlopen(url).read().decode('utf-8')
statusInfo = json.loads(statusJson)
if statusInfo['reply_code'] == 1:
return 1
elif statusInfo['reply_code'] == 0:
if statusInfo['rows'][0]['username'] == username:
return 0
else:
return 2
def logOut(url):
urllib.request.urlopen(url)
print("Current wrong user logged out.")
def logIn(url, userinfo):
logInJson = urllib.request.urlopen(url + urllib.parse.urlencode(userinfo)).read().decode('utf-8')
logInInfo = json.loads(logInJson)
if logInInfo['reply_code'] == 1:
print("Log in success")
else:
print(logInInfo['reply_msg'])
return 0
def runKeep(args):
urlsJson = open('urls.json')
urls = json.loads(urlsJson.read())
urlsJson.close()
user = {'username': args.username, 'password': args.password}
while True:
status = checkStatus(urls['checkStatus'], args.username)
if status == 0:
print("Correct user")
elif status == 1:
print("Logged out")
elif status == 2:
print("Wrong user")
if status == 0:
pass
else:
if status == 2 and args.mode == 'REPLACE':
print("Replacing...")
logOut(urls['logOut'])
time.sleep(3)
logIn(urls['logIn'], user)
print("Login")
time.sleep(60)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="为了解决南大弱智网络中心给一间宿舍一个IP造成的舍友异地登陆后的断网问题")
parser.add_argument('-u', '--username', required=True, help='username')
parser.add_argument('-p', '--password', required=True, help='password')
parser.add_argument('-m', '--mode', help='r: replace if wrong user login')
args = parser.parse_args()
runKeep(args)