-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfdu_network_auto_auth.py
89 lines (67 loc) · 2.13 KB
/
fdu_network_auto_auth.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
import time
import datetime
import random
import threading
import base64
import os
import requests
from account_config import *
url = r'http://10.108.255.249/include/auth_action.php'
random.seed(time.time())
def do_login():
print("Do Login")
# print('username: ' + base64.b64decode(b64username))
# print('password: ' + base64.b64decode(b64password))
get_user_ip_cmd = """
ifconfig | grep "inet" | grep -e '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | grep 10\.[0-9]*\.[0-9]*\.[0-9]* | awk '{ print $2 }' | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'
"""
user_ip = os.popen(get_user_ip_cmd).read().strip()
print("Your IP address is {0}".format(user_ip))
payload = {
'action': 'login',
'username': base64.b64decode(b64username),
'password': base64.b64decode(b64password),
'ac_id': 1,
'user_ip': user_ip,
'nas_ip': '',
'user_mac': '',
'save_me': 0,
'ajax': 1,
}
response = requests.post(url, data=payload)
response_str = response.content.decode('utf-8')
if (response_str.find("login_ok") == -1):
return False
return True
def do_logout():
print("Do Logout")
payload = {
'action': 'logout',
'username': '',
'ajax': 1}
response = requests.post(url, data=payload)
def test_network():
retry_times = 3
for i in range(retry_times):
ret_code = os.system("ping www.baidu.com -c 1 -W 1")
if ret_code == 0:
log("Ping success")
return True
log("Ping failed after {0} times".format(retry_times))
return False
def log(msg):
print("{time}: {msg}".format(time=datetime.datetime.now(), msg=msg))
def start_making_request():
while True:
if (not test_network()):
log("Network connection is bad, try to relogin")
do_logout()
if do_login():
log("Login success")
else:
log("Login fail")
# sleep 1 minute
sleep_seconds = 60
time.sleep(sleep_seconds)
if __name__ == '__main__':
threading.Thread(target=start_making_request).start()