-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
55 lines (37 loc) · 1.13 KB
/
test.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
#!/usr/bin/env python3
import socket
import random
import time
import code
colors = [
b'\x00\x00\xff',
b'\x00\xff\xff',
b'\xff\xff\xff',
b'\xff\x00\xff',
b'\x00\xff\x00',
b'\xff\xff\x00',
b'\xff\x00\x00'
]
CMD_OPEN = b"\x00"
CMD_CLOSE= b"\x01"
CMD_RESIZE = b"\x02"
CMD_DRAW = b"\x03"
s = socket.create_connection(("192.168.1.47",18455))
def send(data):
packlen = len(data) + 4 #header size
msg = packlen.to_bytes(4,'big') + data
print("sending %s" % (" ".join([hex(i) for i in msg])))
s.send(msg)
def win_open(w=16,h=2,x=5,y=9,sw=16,sh=2):
send(CMD_OPEN + w.to_bytes(2,'big') + h.to_bytes(2,'big') + x.to_bytes(2,'big') + y.to_bytes(2,'big') + sw.to_bytes(2,'big') + sh.to_bytes(2,'big'))
def win_close():
send(CMD_CLOSE)
def win_change(w=16,h=2,x=5,y=9,sw=16,sh=2):
send(CMD_RESIZE + w.to_bytes(2,'big') + h.to_bytes(2,'big') + x.to_bytes(2,'big') + y.to_bytes(2,'big') + sw.to_bytes(2,'big') + sh.to_bytes(2,'big'))
def r(times=1):
return b"".join([random.choice(colors) for i in range(times)])
def rainbow(length=120):
for i in range(length):
send(CMD_DRAW + r(4))
time.sleep(1/60)
code.interact(local=locals())