-
Notifications
You must be signed in to change notification settings - Fork 44
/
always_online.py
34 lines (29 loc) · 971 Bytes
/
always_online.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
import os
import time
from BitSrunLogin.LoginManager import LoginManager
def is_connect_internet(testip):
status = os.system(u"ping {} -c 8".format(testip))
return status == 0
def always_login(username, password, testip, checkinterval):
lm = LoginManager()
login = lambda : lm.login(username=username, password=password)
timestamp = lambda : print(time.asctime(time.localtime(time.time())))
timestamp()
try:
login()
except Exception:
pass
while 1:
time.sleep(checkinterval)
if not is_connect_internet(testip):
timestamp()
try:
login()
except Exception:
pass
if __name__ == "__main__":
username = "Your srun account name"
password = "Your password"
testip = "114.114.114.114" # IP to test whether the Internet is connected
checkinterval = 5 * 60
always_login(username, password, testip, checkinterval)