-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitlog.py
73 lines (62 loc) · 1.93 KB
/
bitlog.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
# -*- coding:utf-8 -*-
import cookielib
import md5
import re
import sys
import urllib
import urllib2
# 登录和注销
def log_in(user, password, sta=0):
# 处理Cookie信息
cj = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
# 把密码进行MD5加密
a = md5.new(password)
pswd = a.hexdigest()
login_pswd = pswd[8:-8]
log_url = 'http://10.0.0.55/cgi-bin/do_login'#post_url
login_info = {
'drop' : sta, # 1为仅访问免费资源,0为可以使用国际流量
'n' : 100, # 100为正常登陆,1为强制注销
'password' : login_pswd,
'type': 1,
'username' : user}
req = urllib2.Request(
log_url,
urllib.urlencode(login_info))
resp = urllib2.urlopen(req)
revalue = resp.read() # 读取返回信息
if re.search('[^a-z]',revalue[0:1]): # 登陆成功
return 'succeed'
else:
return revalue
def log_out(user, password):
log_url = 'http://10.0.0.55/cgi-bin/force_logout'
logout_info = {
'drop' : 0, # 1为仅访问免费资源,0为可以使用国际流量
'n' : 1, # 100为正常登陆,1为强制注销
'password' : password,
'type': 1,
'username' : user}
req = urllib2.Request(
log_url,
urllib.urlencode(logout_info))
resp = urllib2.urlopen(req)
revalue = resp.read()
return revalue # 返回注销结果
user = 'your account'
pswd = 'your password'
def main(argv):
if argv[0] == 'in':
if len(argv) == 2 and argv[1] == '1':
print 'international website will not be available'
print log_in(user, pswd, 1)
else:
print log_in(user, pswd)
elif argv[0] == 'out':
print log_out(user, pswd)
else:
print 'what do you want to do: log in or log out?'
if __name__ == '__main__':
main(sys.argv[1:])