Connections

Module for connections to GVM server daemons like gvmd and ospd.

class gvm.connections.GvmConnection(timeout=60)

Base class for establishing a connection to a remote server daemon.

Parameters

timeout (Optional[int]) – Timeout in seconds for the connection. None to wait indefinitely

connect()

Establish a connection to a remote server

disconnect()

Disconnect and close the connection to the remote server

finish_send()

Indicate to the remote server you are done with sending data

read()

Read data from the remote server

Returns

data as utf-8 encoded string

Return type

str

send(data)

Send data to the connected remote server

Parameters

data (Union[bytes, str]) – Data to be send to the server. Either utf-8 encoded string or bytes.

Return type

None

class gvm.connections.SSHConnection(*, timeout=60, hostname='127.0.0.1', port=22, username='gmp', password='', known_hosts_file=None)

SSH Class to connect, read and write from GVM via SSH

Parameters
  • timeout (Optional[int]) – Timeout in seconds for the connection.

  • hostname (Optional[str]) – DNS name or IP address of the remote server. Default is 127.0.0.1.

  • port (Optional[int]) – Port of the remote SSH server. Default is port 22.

  • username (Optional[str]) – Username to use for SSH login. Default is “gmp”.

  • password (Optional[str]) – Passwort to use for SSH login. Default is “”.

connect()

Connect to the SSH server and authenticate to it

Return type

None

disconnect()

Disconnect and close the connection to the remote server

Return type

None

finish_send()

Indicate to the remote server you are done with sending data

read()

Read data from the remote server

Returns

data as utf-8 encoded string

Return type

str

send(data)

Send data to the connected remote server

Parameters

data (Union[bytes, str]) – Data to be send to the server. Either utf-8 encoded string or bytes.

Return type

int

class gvm.connections.TLSConnection(*, certfile=None, cafile=None, keyfile=None, hostname='127.0.0.1', port=9390, password=None, timeout=60)

TLS class to connect, read and write from a remote GVM daemon via TLS secured socket.

Parameters
  • timeout (Optional[int]) – Timeout in seconds for the connection.

  • hostname (Optional[str]) – DNS name or IP address of the remote TLS server.

  • port (Optional[int]) – Port for the TLS connection. Default is 9390.

  • certfile (Optional[str]) – Path to PEM encoded certificate file. See python certificates for details.

  • cafile (Optional[str]) – Path to PEM encoded CA file. See python certificates for details.

  • keyfile (Optional[str]) – Path to PEM encoded private key. See python certificates for details.

  • password (Optional[str]) – Password for the private key. If the password argument is not specified and a password is required it will be interactively prompt the user for a password.

connect()

Establish a connection to a remote server

disconnect()

Disconnect and close the connection to the remote server

finish_send()

Indicate to the remote server you are done with sending data

read()

Read data from the remote server

Returns

data as utf-8 encoded string

Return type

str

send(data)

Send data to the connected remote server

Parameters

data (Union[bytes, str]) – Data to be send to the server. Either utf-8 encoded string or bytes.

Return type

None

class gvm.connections.UnixSocketConnection(*, path='/var/run/gvmd.sock', timeout=60)

UNIX-Socket class to connect, read, write from a GVM server daemon via direct communicating UNIX-Socket

Parameters
  • path (Optional[str]) – Path to the socket. Default is “/var/run/gvmd.sock”.

  • timeout (Optional[int]) – Timeout in seconds for the connection. Default is 60 seconds.

connect()

Connect to the UNIX socket

Return type

None

disconnect()

Disconnect and close the connection to the remote server

finish_send()

Indicate to the remote server you are done with sending data

read()

Read data from the remote server

Returns

data as utf-8 encoded string

Return type

str

send(data)

Send data to the connected remote server

Parameters

data (Union[bytes, str]) – Data to be send to the server. Either utf-8 encoded string or bytes.

Return type

None

class gvm.connections.DebugConnection(connection)

Wrapper around a connection for debugging purposes

Allows to debug the connection flow including send and read data. Internally it uses the python logging framework to create debug messages. Please take a look at the logging tutorial for further details.

Usage example:

import logging

logging.basicConfig(level=logging.DEBUG)

socketconnection = UnixSocketConnection(path='/var/run/gvm.sock')
connection = DebugConnection(socketconnection)
gmp = Gmp(connection=connection)
Parameters

connection (GvmConnection) – GvmConnection to observe