-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_remote.py
77 lines (73 loc) · 2.41 KB
/
server_remote.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
74
75
76
77
from PIL import ImageGrab
from subprocess import *
from Tkinter import *
from socket import *
import win32api, win32con
import Image, ImageTk
import thread
import os
PORT = 9000
LPORT = PORT + 10
liveuser = []
cflag = 0
sock = socket(AF_INET, SOCK_STREAM)
sock.bind(("", PORT))
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
sock.listen(1)
#socket for checking live nodes
slive = socket(AF_INET, SOCK_DGRAM)
slive.bind(("", LPORT))
def main():
global cflag
#starting thread for accepting msg from live nodes
#thread.start_new_thread(recieve,())
#sending msg to all nodes connected
#connected()
#main code
conn,addr = sock.accept()
print gethostname() + ' Connected by: ',gethostbyname(addr[0])
#print '1'
while True:
try:
#taking screenshot
ImageGrab.grab().save("images\\img1.jpg", "JPEG")
#sending image to client
fp = open("images\\img1.jpg","rb")
data = fp.read()#binary form reading
fp.close()
conn.sendall(data)
#print '2'
#recieving mouse coordinates or keypressed
rec = conn.recv(1024)
#print rec
while rec != "start":
if '~' in rec:
lr = rec[0]
rec = rec[1:]
# print '3'
x,y = map(int, rec.split('~'))
#mouse pos. set nd single click done
win32api.SetCursorPos((x,y))
if lr == 'l':
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
elif lr == 'r':
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,x,y,0,0)
elif rec == 'close':
cflag = 1
break
elif rec:
keypress = int(rec)
# print '4'
#particular key pressed
win32api.keybd_event(keypress,0,0,0)
rec = conn.recv(1024)
except:
continue
if cflag == 1:
break
main()
for i in liveuser:
slive.sendto("going",(i,LPORT))
# print '5'