├── 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 |