├── requirements.txt ├── README.md ├── LICENSE ├── .gitignore ├── app.py ├── vnc.py ├── web └── index.html └── input_manager.py /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FurySwordXD/VNC/HEAD/requirements.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VNC 2 | 3 | Just run app.py 4 | 5 | For connections through the internet you may have to portforward the ports 7000 and 6969 to your machines ip. 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 FurySwordXD 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | .vscode/ 106 | 107 | http/ 108 | tcp_sockets/ 109 | threaded_sockets/ 110 | udp_sockets/ 111 | 112 | client.py 113 | host.py -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import eel 2 | from vnc import VNC 3 | from threading import Thread 4 | import atexit 5 | import sys 6 | 7 | from input_manager import InputManager 8 | from vnc import VNC 9 | 10 | status = 'None' 11 | connection = 'None' 12 | vnc = VNC() 13 | input_manager = InputManager() 14 | 15 | eel.init('web') 16 | 17 | @eel.expose 18 | def host(): 19 | global status 20 | global vnc 21 | global transmit_thread 22 | global input_manager 23 | 24 | print('Hosting...') 25 | status = 'host' 26 | 27 | transmit_thread = Thread(target=vnc.transmit) 28 | transmit_thread.daemon = True 29 | transmit_thread.start() 30 | 31 | input_thread = Thread(target=input_manager.receive_input, args=[]) 32 | input_thread.daemon = True 33 | input_thread.start() 34 | 35 | @eel.expose 36 | def stop_host(): 37 | global status 38 | status = 'None' 39 | print("Stopping server...") 40 | 41 | @eel.expose 42 | def connect(ip): 43 | global status 44 | global vnc 45 | global connection 46 | print('Connecting...') 47 | status = 'client' 48 | vnc.ip = ip 49 | input_manager.ip = ip 50 | try: 51 | vnc.start_receive() 52 | input_manager.connect_input() 53 | connection = 'active' 54 | except Exception as e: 55 | print('Connection failed...') 56 | 57 | @eel.expose 58 | def transmit_input(data, event_type): 59 | if status == 'client': 60 | if event_type == 'keydown': 61 | input_manager.transmit_input(keydown=data) 62 | pass 63 | elif event_type == 'keyup': 64 | input_manager.transmit_input(keyup=data) 65 | pass 66 | elif event_type == 'mousemove': 67 | #print(data) 68 | input_manager.transmit_input(mouse_pos=data) 69 | pass 70 | elif event_type == 'mousedown': 71 | #print(data) 72 | input_manager.transmit_input(mouse_pos=data['pos'], mouse_down=data['button']) 73 | elif event_type == 'mouseup': 74 | #print(data) 75 | input_manager.transmit_input(mouse_pos=data['pos'], mouse_up=data['button']) 76 | 77 | eel.start('index.html', block=False, port=8080) 78 | 79 | while True: 80 | 81 | if status == 'host': 82 | eel.updateScreen(vnc.image_serializer().decode()) 83 | elif status == 'client': 84 | if connection == 'active': 85 | eel.updateScreen(vnc.receive()) 86 | 87 | eel.sleep(.01) -------------------------------------------------------------------------------- /vnc.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | from io import BytesIO 3 | import socket 4 | import mss 5 | import base64 6 | import struct 7 | import time 8 | 9 | class VNC: 10 | 11 | def __init__(self, ip='0.0.0.0', port=7000): 12 | self.ip = ip 13 | self.port = port 14 | 15 | def screenshot(self): 16 | with mss.mss() as sct: 17 | img = sct.grab(sct.monitors[1]) 18 | return self.rgba_to_rgb(img) 19 | 20 | def rgba_to_rgb(self, image): 21 | return Image.frombytes('RGB', image.size, image.bgra, 'raw', 'BGRX') 22 | 23 | def image_serializer(self, resolution=(1600, 900)): 24 | image = self.screenshot().resize(resolution, Image.ANTIALIAS) 25 | buffer = BytesIO() 26 | image.save(buffer, format='jpeg') 27 | data_string = base64.b64encode(buffer.getvalue()) 28 | return data_string 29 | 30 | def image_deserializer(self, image_string): 31 | return Image.open(BytesIO(base64.b64decode(image_string))) 32 | 33 | def send_msg(self, sock, msg): 34 | # Prefix each message with a 4-byte length (network byte order) 35 | msg = struct.pack('>I', len(msg)) + msg 36 | sock.sendall(msg) 37 | 38 | def recv_msg(self, sock): 39 | # Read message length and unpack it into an integer 40 | raw_msglen = self.recvall(sock, 4) 41 | if not raw_msglen: 42 | return None 43 | msglen = struct.unpack('>I', raw_msglen)[0] 44 | # Read the message data 45 | return self.recvall(sock, msglen) 46 | 47 | def recvall(self, sock, n): 48 | # Helper function to recv n bytes or return None if EOF is hit 49 | data = b'' 50 | while len(data) < n: 51 | packet = sock.recv(n - len(data)) 52 | if not packet: 53 | return None 54 | data += packet 55 | return data 56 | 57 | def transmit(self): 58 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sender: 59 | sender.bind((self.ip, self.port)) 60 | sender.listen() 61 | print('Waiting for connection...') 62 | conn, addr = sender.accept() 63 | with conn: 64 | print('Connected by', addr) 65 | while True: 66 | #start_time = time.time() 67 | self.send_msg(conn, self.image_serializer()) 68 | #print(self.data_string) 69 | #print("FPS: ", 1/(time.time() - start_time)) 70 | 71 | def start_receive(self): 72 | self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 73 | self.conn.connect((self.ip, self.port)) 74 | print("Connected to ", self.ip, ":", self.port) 75 | 76 | def receive(self): 77 | try: 78 | #start_time = time.time() 79 | data_string = self.recv_msg(self.conn) 80 | return data_string.decode() 81 | #self.image.show() 82 | # print("FPS: ", 1/(time.time() - start_time)) 83 | 84 | except Exception as e: 85 | print(e) 86 | return None 87 | -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |

EEL

16 | 17 |
18 |
VNC
19 |
20 |
21 | 22 |
23 | 24 |
25 |
26 |
27 |
28 |
29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 |
37 | 38 |
39 |
40 | 41 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /input_manager.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import time 3 | import pyautogui 4 | import struct 5 | from pynput import mouse 6 | from pynput import keyboard 7 | 8 | class InputManager: 9 | 10 | def __init__(self, ip='0.0.0.0', port=6969): 11 | self.input = { 12 | "mouse_pos": [0.0, 0.0], 13 | "lmb": False, 14 | "rmb": False, 15 | "keys": [], 16 | } 17 | self.ip = ip 18 | self.port = port 19 | 20 | def send_msg(self, sock, msg): 21 | # Prefix each message with a 4-byte length (network byte order) 22 | msg = struct.pack('>I', len(msg)) + msg 23 | sock.sendall(msg) 24 | 25 | def recv_msg(self, sock): 26 | # Read message length and unpack it into an integer 27 | raw_msglen = self.recvall(sock, 4) 28 | if not raw_msglen: 29 | return None 30 | msglen = struct.unpack('>I', raw_msglen)[0] 31 | # Read the message data 32 | return self.recvall(sock, msglen) 33 | 34 | def recvall(self, sock, n): 35 | # Helper function to recv n bytes or return None if EOF is hit 36 | data = b'' 37 | while len(data) < n: 38 | packet = sock.recv(n - len(data)) 39 | if not packet: 40 | return None 41 | data += packet 42 | return data 43 | 44 | def set_resolution(self, width=1280, height=720): 45 | self.width = width 46 | self.height = height 47 | #print(self.width, self.height) 48 | 49 | def motion(self, event): 50 | self.input["mouse_pos"] = [event.x/self.width, event.y/self.height] 51 | self.send_msg(self.conn, str(self.input).encode()) 52 | 53 | def key_pressed(self, event): 54 | print("Key Press: ", repr(event.char)) 55 | self.input["keys"].append(repr(event.char)) 56 | self.input["keys"] = list(set(self.input["keys"])) 57 | self.send_msg(self.conn, str(self.input).encode()) 58 | 59 | def key_released(self, event): 60 | print("Key Released: ", repr(event.char)) 61 | try: 62 | self.input["keys"].remove(repr(event.char)) 63 | finally: 64 | self.send_msg(self.conn, str(self.input).encode()) 65 | 66 | def left_click_pressed(self, event): 67 | self.input["mouse_pos"] = [event.x/self.width, event.y/self.height] 68 | self.input["lmb"] = True 69 | self.send_msg(self.conn, str(self.input).encode()) 70 | 71 | def left_click_released(self, event): 72 | self.input["mouse_pos"] = [event.x/self.width, event.y/self.height] 73 | self.input["lmb"] = False 74 | self.send_msg(self.conn, str(self.input).encode()) 75 | 76 | def right_click_pressed(self, event): 77 | self.input["mouse_pos"] = [event.x/self.width, event.y/self.height] 78 | self.input["rmb"] = True 79 | self.send_msg(self.conn, str(self.input).encode()) 80 | 81 | def right_click_released(self, event): 82 | self.input["mouse_pos"] = [event.x/self.width, event.y/self.height] 83 | self.input["rmb"] = False 84 | self.send_msg(self.conn, str(self.input).encode()) 85 | 86 | def transmit(self): 87 | self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 88 | self.conn.connect((self.ip, self.port)) 89 | print("Connected to ", self.ip, ":", self.port) 90 | # while True: 91 | # #print(self.input["mouse_pos"]) 92 | # conn.send(str(self.input).encode()) 93 | # conn.recv(10) 94 | 95 | def receive(self): 96 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sender: 97 | 98 | sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 99 | sender.bind((self.ip, self.port)) 100 | sender.listen() 101 | print('Waiting for connection on port('+ str(self.port) +')...') 102 | conn, addr = sender.accept() 103 | 104 | with conn: 105 | print('Connected by', addr) 106 | 107 | width, height = pyautogui.size() 108 | print(width, height) 109 | mouse_var = mouse.Controller() 110 | keyboard_var = keyboard.Controller() 111 | last_mouse_input = [0,0] 112 | while True: 113 | #start_time = time.time() 114 | received_input = eval(self.recv_msg(conn).decode()) 115 | mouse_input = received_input["mouse_pos"] 116 | mouse_input[0] = mouse_input[0] * width 117 | mouse_input[1] = mouse_input[1] * height 118 | #print(received_input) 119 | if mouse_input != last_mouse_input: 120 | mouse_var.position = tuple(mouse_input) 121 | last_mouse_input = mouse_input 122 | #print(received_input) 123 | if received_input['lmb']: 124 | #mouse_var.press(mouse.Button.left) 125 | mouse_var.click(mouse.Button.left) 126 | print("LMB") 127 | #else: 128 | # mouse_var.release(mouse.Button.left) 129 | if received_input['rmb']: 130 | #mouse_var.press(mouse.Button.right) 131 | mouse_var.click(mouse.Button.right) 132 | print("RMB") 133 | #else: 134 | # mouse_var.release(mouse.Button.right) 135 | for k in received_input['keys']: 136 | print(eval(k)) 137 | keyboard_var.press(str(eval(k))) 138 | 139 | #EEL 140 | 141 | def connect_input(self): 142 | self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 143 | self.conn.connect((self.ip, self.port)) 144 | print("Connected to ", self.ip, ":", self.port) 145 | 146 | def transmit_input(self, mouse_pos = None, mouse_down = None, mouse_up = None, keydown = None, keyup = None): 147 | key_input = { 148 | "mouse_pos": mouse_pos, 149 | "mouse_down": mouse_down, 150 | "mouse_up": mouse_up, 151 | "keydown": keydown, 152 | "keyup": keyup 153 | } 154 | self.send_msg(self.conn, str(key_input).encode()) 155 | 156 | def receive_input(self): 157 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sender: 158 | 159 | sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 160 | sender.bind((self.ip, self.port)) 161 | sender.listen() 162 | print('Waiting for connection on port('+ str(self.port) +')...') 163 | conn, addr = sender.accept() 164 | 165 | with conn: 166 | print('Connected by', addr) 167 | 168 | width, height = pyautogui.size() 169 | print(width, height) 170 | mouse_controller = mouse.Controller() 171 | keyboard_controller = keyboard.Controller() 172 | 173 | mouse_buttons = [mouse.Button.left, mouse.Button.middle, mouse.Button.right] 174 | 175 | while True: 176 | #start_time = time.time() 177 | try: 178 | received_input = eval(self.recv_msg(conn).decode()) 179 | print(received_input) 180 | 181 | mouse_input = received_input['mouse_pos'] 182 | if mouse_input: 183 | mouse_input[0] = mouse_input[0] * width 184 | mouse_input[1] = mouse_input[1] * height 185 | 186 | mouse_controller.position = tuple(mouse_input) 187 | 188 | if received_input['mouse_down'] == 0: 189 | mouse_controller.press(mouse.Button.left) 190 | 191 | if received_input['mouse_up'] == 0: 192 | mouse_controller.release(mouse.Button.left) 193 | 194 | if received_input['mouse_down'] == 2: 195 | mouse_controller.press(mouse.Button.right) 196 | 197 | if received_input['mouse_up'] == 2: 198 | mouse_controller.release(mouse.Button.right) 199 | 200 | if received_input['keydown']: 201 | keyboard_controller.press(keyboard.KeyCode(received_input['keydown'])) 202 | 203 | if received_input['keyup']: 204 | keyboard_controller.release(keyboard.KeyCode(received_input['keyup'])) 205 | 206 | except Exception as e: 207 | print(e) 208 | pass --------------------------------------------------------------------------------