Skip to content

Instantly share code, notes, and snippets.

@eddywebs
Created April 11, 2025 17:25
Show Gist options
  • Save eddywebs/83a4448480a9e6fedd89d2941ecca8b7 to your computer and use it in GitHub Desktop.
Save eddywebs/83a4448480a9e6fedd89d2941ecca8b7 to your computer and use it in GitHub Desktop.
import socket
import struct
class VNCServer:
def __init__(self, host='localhost', port=5900):
self.host = host
self.port = port
self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server_socket.bind((self.host, self.port))
self.server_socket.listen(1)
def start(self):
print(f"VNC Server listening on {self.host}:{self.port}")
while True:
client_socket, addr = self.server_socket.accept()
print(f"Connection from {addr}")
self.handle_client(client_socket)
def handle_client(self, client_socket):
# Send ProtocolVersion message
client_socket.send(b"RFB 003.008\n")
# Receive client protocol version
client_version = client_socket.recv(12).decode().strip()
print(f"Client version: {client_version}")
# Send security types
client_socket.send(struct.pack("!BB", 1, 1)) # 1 security type, type 1 (None)
# Receive security type chosen by client
security_type = struct.unpack("!B", client_socket.recv(1))[0]
print(f"Security type chosen: {security_type}")
# Send SecurityResult message
client_socket.send(struct.pack("!I", 0)) # 0 means OK
# TODO: Implement the rest of the RFB protocol...
if __name__ == "__main__":
server = VNCServer()
server.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment