post.py
3.8 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/python
#-*-coding:utf-8-*-
import httplib,urllib;
import json
import os
import sys
import time
import random
host = "127.0.0.1:2123"
NetType_Wifi = 1
NetType_2G = 2
NetType_3G = 3
NetType_4G = 4
NetType_Wire = 5
SysType_Andriod = 1
SysType_IOS = 2
Systype_PC = 3
def active_room(conn, headers, roomid):
body = {}
js = {}
js["100"] = "1"
js["101"] = "2"
js["102"] = "3"
body["roomid"] = int(roomid)
body["active_time"] = int(time.time()) + 3600*3
body["teachers"] = str(js).replace("'","\"")
body["max_count"] = 100
pa = json.dumps(body)
print "post: ", pa
conn.request(method="POST", url="/active_room", body=pa, headers=headers);
response = conn.getresponse();
print "resp:",response.status
data = response.read()
if response.status == 200:
print "发布成功!";
else:
print "发布失败";
print "data:",data
d = eval(data)
print d
def enter_room(conn, headers, roomid, uid):
body = {}
client = {}
client["brand"] = "Xiaomi"
client["model"] = "MI 2"
client["ver"] = 200100
client["net_type"] = NetType_Wifi
client["sys_type"] = SysType_IOS
body["roomid"] = roomid
body["uid"] = uid
body["ip"] = "127.0.0.3"
body["data"] = str(client).replace("'","\"")
pa = json.dumps(body)
print "post: ", pa
conn.request(method="POST", url="/enter_room", body=pa, headers=headers);
response = conn.getresponse();
print "resp:",response.status
data = response.read()
if response.status == 200:
print "发布成功!";
else:
print "发布失败";
print "data:",data
d = eval(data)
print d
def set_room(conn, headers, status, num):
body = {}
body["roomid"] = 10001
body["status"] = status
body["max_count"] = num
pa = json.dumps(body)
print "post: ", pa
conn.request(method="POST", url="/set_room", body=pa, headers=headers);
response = conn.getresponse();
print "resp:",response.status
data = response.read()
if response.status == 200:
print "发布成功!";
else:
print "发布失败";
print "data:",data
d = eval(data)
print d
def get_roomlist(conn, headers):
body = {}
pa = json.dumps(body)
print "post: ", pa
conn.request(method="POST", url="/get_roomlist", body=pa, headers=headers);
response = conn.getresponse();
print "resp:",response.status
data = response.read()
if response.status == 200:
print "发布成功!";
else:
print "发布失败";
print "data:",data
d = eval(data)
print d
def update_mgr(conn, headers):
pass
def tester(argv1, argv2):
me = argv1
headers = {"Content-Type":"application/json;charset=utf-8", "Connection":"Keep-Alive"}
conn = httplib.HTTPConnection(host)
if me == "open":
active_room(conn, headers, argv2)
elif me == "enter":
enter_room(conn, headers, 10001, 101)
elif me == "lock" or me == "unlock" or me == "close":
set_room(conn, headers, me, argv2)
elif me == "update":
update_mgr(conn, headers)
elif me == "list":
get_roomlist(conn, headers)
def looper():
random.seed(time.time())
headers = {"Content-Type":"application/json;charset=utf-8", "Connection":"Keep-Alive"}
conn = httplib.HTTPConnection(host)
open_dict = {}
roomid = 10
status = ["lock", "unlock","close"]
while True:
time.sleep(1)
r = random.randint(0,100)
if r > 30:
active_room(conn, headers, roomid)
roomid += 1
elif r > 50:
num = random.randint(20,1000)
idx = random.randint(0,2)
set_room(conn, header, status[idx], num)
elif r > 75:
uid = random.randint(23,2093)
enter_room(conn, headers, roomid - 1, uid)
else:
get_roomlist(conn, headers)
if __name__ == "__main__":
argv1 = ""
if len(sys.argv) >= 2:
argv1 = sys.argv[1]
argv2 = ""
if len(sys.argv) > 2:
argv2 = sys.argv[2]
#tester(argv1, argv2)
looper()