sirup.VPNConnector

Connect to a server with OpenVPN

Classes

VPNConnector

Class to connect and disconnect to a single VPN server.

Module Contents

class sirup.VPNConnector.VPNConnector(config_file, auth_file, track_ip=True)[source]

Class to connect and disconnect to a single VPN server.

Parameters:
  • config_file (str) – Full path and file name of the OpenVPN configuration file to connect to a server.

  • auth_file (str) – Full path and file name of the file with the authentication credentials for VPN connections.

  • track_ip (bool, optional) – If True, the IP address is queried after each connect and disconnect. For long-running programs, it is better to set track_ip=False in order to respect the query limits of the IP address API.

config_file

Full path and file name of the OpenVPN configuration file to connect to a server.

Type:

str

auth_file

Full path and file name of the file with the authentication credentials for VPN connections.

Type:

str

current_ip

If track_ip is True, the IP address of the machine that is currently visible.

Type:

None or str

base_ip

If track_ip is True, the IP address when no VPN tunnel is active.

Type:

None or str

track_ip

If True, queries the IP address of the machine after each connect and disconnect.

Type:

bool

__repr__()[source]

Return repr(self).

is_connected()[source]

Indicates whether a VPN connection is active.

Returns:

True if a VPN connection is running.

Return type:

bool

start_vpn(pwd, proc_id=None)[source]

Start an OpenVPN connection.

Starts an OpenVPN process. The log is written to a temporary file. The process is opened as a daemon: This means that the process runs in the background and releases the terminal after start-up.

Parameters:
  • pwd (str) – The user’s root password.

  • proc_id (str, optional) – argument passed with –writepid to OpenVPN. It is the filename to which the ID of the vpn process is written.

Raises:

Exceptions when opening the connection fails. – The exceptions are specified in sirup.raise_ovpn_exceptions.

connect(pwd)[source]

Connect to a server.

Parameters:

pwd (str) – User root password. This is necessary for OpenVPN.

disconnect(pwd)[source]

Disconnect from the current server. If self.track_ip is True, also get back the base IP.

Parameters:

pwd (str) – User root password. This is necessary for OpenVPN.