• This repository has been archived on 20/Jun/2024
  • Stars
    star
    351
  • Rank 120,906 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Complete implementation of VirtualBox's COM API with a Pythonic interface.

virtualbox-python

Complete implementation of VirtualBox's COM API with a Pythonic interface.

Installation

Go to VirtualBox's downloads page (https://www.virtualbox.org/wiki/Downloads) and download the VirtualBox SDK. Within the extracted ZIP file there is a directory called "installer". Open a console within the installer directory and run python vboxapisetup.py install using your system Python. This installs vboxapi which is the interface that talks to VirtualBox via COM.

Next is to install this library:

To get the latest released version of virtualbox from PyPI run the following:

$ python -m pip install virtualbox

or to install the latest development version from GitHub:

$ git clone https://github.com/sethmlarson/virtualbox-python
$ cd virtualbox-python
$ python setup.py install

Getting Started

Listing Available Machines

>>> import virtualbox
>>> vbox = virtualbox.VirtualBox()
>>> [m.name for m in vbox.machines]
["windows"]

Launching a Machine

>>> session = virtualbox.Session()
>>> machine = vbox.find_machine("windows")
>>> # progress = machine.launch_vm_process(session, "gui", "")
>>> # For virtualbox API 6_1 and above (VirtualBox 6.1.2+), use the following:
>>> progress = machine.launch_vm_process(session, "gui", [])
>>> progress.wait_for_completion()

Querying the Machine

>>> session.state
SessionState(2)  # locked
>>> machine.state
MachineState(5)  # running
>>> height, width, _, _, _, _ = session.console.display.get_screen_resolution()

Interacting with the Machine

>>> session.console.keyboard.put_keys("Hello, world!")
>>> guest_session = session.console.guest.create_session("Seth Larson", "password")
>>> guest_session.directory_exists("C:\\Windows")
True
>>> proc, stdout, stderr = guest_session.execute("C:\\\\Windows\\System32\\cmd.exe", ["/C", "tasklist"])
>>> print(stdout)
Image Name                   PID Session Name     Session#    Mem Usage
========================= ====== ================ ======== ============
System Idle Process            0 Console                 0         28 K
System                         4 Console                 0        236 K
smss.exe                     532 Console                 0        432 K
csrss.exe                    596 Console                 0      3,440 K
winlogon.exe                 620 Console                 0      2,380 K
services.exe                 664 Console                 0      3,780 K
lsass.exe                    676 Console                 0      6,276 K
VBoxService.exe              856 Console                 0      3,972 K
svchost.exe                  900 Console                 0      4,908 K
svchost.exe                 1016 Console                 0      4,264 K
svchost.exe                 1144 Console                 0     18,344 K
svchost.exe                 1268 Console                 0      2,992 K
svchost.exe                 1372 Console                 0      3,948 K
spoolsv.exe                 1468 Console                 0      4,712 K
svchost.exe                 2000 Console                 0      3,856 K
wuauclt.exe                  400 Console                 0      7,176 K
alg.exe                     1092 Console                 0      3,656 K
wscntfy.exe                 1532 Console                 0      2,396 K
explorer.exe                1728 Console                 0     14,796 K
wmiprvse.exe                1832 Console                 0      7,096 K
VBoxTray.exe                1940 Console                 0      3,196 K
ctfmon.exe                  1948 Console                 0      3,292 K
cmd.exe                     1284 Console                 0      2,576 K
tasklist.exe                 124 Console                 0      4,584 K

Registering Event Handlers

>>> def test(event):
>>>    print("scancode received: %r" % event.scancodes)
>>>
>>> session.console.keyboard.set_on_guest_keyboard(test)
140448201250560
scancode received: [35]
scancode received: [23]
scancode received: [163]
scancode received: [151]
scancode received: [57]

Powering-Down a Machine

>>> session.console.power_down()

License

Apache-2.0

More Repositories

1

secure-python-package-template

Template for a Python package with a secure project host and package repository configuration.
Python
186
star
2

truststore

Verify certificates using OS trust stores
Python
157
star
3

trytravis

Send local git changes to Travis CI without commits or pushes.
Python
130
star
4

pypi-data

Data about packages and maintainers on PyPI
Python
103
star
5

socksio

Sans-I/O implementation of SOCKS4, SOCKS4A, and SOCKS5
Python
52
star
6

trustme-cli

A simple tool that generates certificates for local testing
Python
35
star
7

diagrams

Collection of diagrams from articles
Python
28
star
8

utf8.xyz

A quick web app for fetching Unicode characters without extra fluff
HTML
26
star
9

sethmlarson.dev

Personal blog
HTML
23
star
10

pycon-async-sync-poster

An example project which demonstrates how to use some new tools to more easily maintain a codebase that supports both async and synchronous I/O and multiple async libraries.
Python
22
star
11

whatwg-url

Python implementation of WHATWG URL Living Standard
Python
20
star
12

selectors2

Backported, durable, and portable selectors designed to replace the standard library selectors module.
Python
14
star
13

pypi-scorecards

OpenSSF Scorecard for top Python packages
Python
13
star
14

irl

URLs for IRL
Python
10
star
15

hstspreload

Chromium HSTS Preload list as a Python package and updated daily.
Python
10
star
16

pip-sbom

Generate Software Bill-of-Materials (SBOMs) for Python environments from distribution metadata
Python
9
star
17

avail

Check the availability of names in common places
Python
9
star
18

psl

Mozilla Public Suffix list as a Python package and updated daily.
Python
8
star
19

mashpack

Mashpack - JSON-Object Serialization and Compression
Python
6
star
20

cpython-sbom

Generating Software Bill-of-Materials (SBOM) for CPython release artifacts
Python
6
star
21

rfc6555

Python implementation of the Happy Eyeballs Algorithm described in RFC 6555
Python
4
star
22

sethmlarson

GitHub README.md
Python
4
star
23

fix-python-repl-exit

A simple script that makes typing `exit` in a Python interpreter do what you expect
Python
3
star
24

capture-packets

User-friendly packet captures
Python
3
star
25

delt

Builds and uploads Continuous Integration environment reports
Python
3
star
26

quic-qpack

Pure Python implementation of QPACK: An efficient encoding for HTTP headers for HTTP/3
2
star
27

picklepipe

Python pickling protocol over any network interface.
Python
2
star
28

eland-demo-pycon2022

Jupyter Notebook
1
star
29

verify-python-release-signatures

Verify Python release signatures
Python
1
star
30

python-travis-deploy

A test project for deploying to PyPI from Travis
Python
1
star