-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrComWeb.py
More file actions
69 lines (55 loc) · 1.86 KB
/
DrComWeb.py
File metadata and controls
69 lines (55 loc) · 1.86 KB
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
# -*- coding : utf-8 -*-
import os
import time
import requests
import subprocess
# enter the username and password of your drcom account here
username=""
upass=""
# urls for login
# In different college, it is different
# but you can find out what it is by doing:
# 1. use your cellphone to connect to the wifi of your computer or of your campus
# 2. visit a website, such as baidu, then the browser should jump to the login page
# 3. copy the address of this login page, and paste it to the LoginUrl below.
LoginUrl = "http://172.30.255.2/a30.htm"
LogoutUrl = "http://172.30.255.2/F.htm"
ZeroMKKey = '123456'
# www.baidu.com ; www.so.com
# here is the ip addresses that used to ping, so we can find out if we are online.
# you can use ";" to seperate the ip addresses that you want to use to ping.
PingIpAddresses = "125.88.193.243;202.108.22.5"
SleepTime = 5
def login():
data = {"DDDDD":username, 'upass':upass, '0MKKey':ZeroMKKey}
r = requests.post(LoginUrl, data)
if r.status_code == 200:
print u"login successfully!"
else:
print u"login failed"
return r
def logout():
r = requests.get(LogoutUrl)
if r.status_code != 200:
print u"logout failed"
else:
print u"logout successfully"
return r
def ping_ips(ips):
for ip in ips.split(";"):
ret = subprocess.Popen("ping -n 1 -w 1 %s " % ip, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ret.communicate()
if ret.returncode == 0:
print "ping %s...successful!" % ip
return True
else:
print "ping %s...failed!" % ip
return False
def keep_login():
while True:
if ping_ips(PingIpAddresses) == False:
login()
else:
time.sleep(SleepTime)
if __name__ == "__main__":
keep_login()