Skip to main content

Asynchronous VNC for Python v2

Project description

https://img.shields.io/badge/source-github-orange https://readthedocs.org/projects/asyncvnc2/badge/?version=latest&style=flat-square https://img.shields.io/pypi/v/asyncvnc2?style=flat-square
This project is a spin-off from the AsyncVNC project, which is still maintained by Barney Gale.

AsyncVNC by Barney Gale

AsyncVNC2 is a Python package which provides an asynchronous client implementation of the VNC (RFB) protocol on top of the asyncio framework.

import asyncio, asyncvnc2

async def run_client():
    with asyncvnc2.connect('localhost', 5900, 'username', 'password') as client:
        client.keyboard.write('hello world!')

asyncio.run(run_client())

Features

  • Full support for keyboard, mouse, video and clipboard updates.

    • The frame buffer can be exported as an RGBA numpy array.

    • Keyboard keys are specified by name or character.

  • Compatibility with traditional VNC servers (RealVNC, TightVNC, TigerVNC, etc).

    • Including unauthenticated connections.

    • Including password authentication with Triple DES.

  • Compatibility with the built-in macOS Remote Desktop server.

    • Including username/password authentication with 2048-bit RSA keys and 128-bit AES.

    • Connects to the desktop, not the login screen.

  • Detection of multi-head frame buffer data using a novel algorithm.

  • Support for tunneling VNC over SSH with AsyncSSH.

  • Support most popular encoding types for image.

    • Raw

    • CopyRect

    • zlib

    • TRLE

    • ZRLE

Installation

This package requires Python 3.7+.

Install AsyncVNC2 by running:

pip install asyncvnc2

Connecting to a server

This snippet connects to a local unauthenticated VNC server, prints information, and disconnects:

import asyncio, asyncvnc2

async def run_client():
    async with asyncvnc2.connect('localhost') as client:
        print(client)

asyncio.run(run_client())

To log in to a macOS server, supply username and password arguments:

async with asyncvnc2.connect('localhost', username='user123', password='h4x0r'):
    ...

For traditional authenticated VNC servers, the password argument is required but not username.

To tunnel VNC over SSH, use the AsyncSSH package (after which this package is modelled):

import asyncio, asyncssh, asyncvnc2

async def run_client():
    async with asyncssh.connect('myserver') as conn:
        async with asyncvnc2.connect('localhost', opener=conn.open_connection) as client:
            print(client)

asyncio.run(run_client())

Sending events

Keyboard and mouse objects provide context managers for holding down keys and buttons:

with client.keyboard.hold('Ctrl'):
    ...

with client.mouse.hold():
    ...

The keyboard has methods for pressing keys and writing text:

client.keyboard.press('Ctrl', 'c')  # keys are stacked
client.keyboard.write('hi there!')  # keys are queued

The mouse has methods for moving the cursor and clicking:

client.mouse.move(100, 200)
client.mouse.click()
client.mouse.right_click()
client.mouse.scroll_up()

Taking a screenshot

To retrieve an image from the VNC server and save it as a PNG file:

import asyncio, asyncvnc2
from PIL import Image

async def run_client():
    async with asyncvnc2.connect('localhost') as client:
        # Retrieve pixels as a 3D numpy array
        pixels = await client.screenshot()

        # Save as PNG using PIL/pillow
        image = Image.fromarray(pixels)
        image.save('screenshot.png')

asyncio.run(run_client())

The macOS VNC server composites attached monitors/screens into a single frame buffer. It does not send updates for unoccupied regions; we can use this information to detect screens:

pixels = client.video.as_rgba()
for screen in client.video.detect_screens():
    screen_pixels = pixels[screen.slices]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncvnc2-2.0.0.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asyncvnc2-2.0.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file asyncvnc2-2.0.0.tar.gz.

File metadata

  • Download URL: asyncvnc2-2.0.0.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for asyncvnc2-2.0.0.tar.gz
Algorithm Hash digest
SHA256 a16d9061dfbedaecf4e42a9925a403a6b1ab47e9c32d0e200be23aadce3a2dbd
MD5 a4985ff5def74667fcf9b41514748889
BLAKE2b-256 9a35d8763136f1bf597d8c0994d3da0e1f11cd099bce64ab67e6ec921705365a

See more details on using hashes here.

File details

Details for the file asyncvnc2-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: asyncvnc2-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for asyncvnc2-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6a996f14ae7836eb16a9c877b2884ababac68469bed3a5eaf418f5dd66f6928
MD5 9099c1c99eafbe8a4c3d08e64a62691e
BLAKE2b-256 e028ac3e36a8676fa8a2b441b279ac3e841964843e6b197c92095619b61cdb43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page