mozvpn package

Submodules

mozvpn.cli module

mozvpn.mozvpn module

Main module.

mozvpn.mozvpn.determine_ip_location(ip: str)Dict[source]

Determine location of IP address.

Parameters

ip – IP address

Returns

dict containing (among others) fields country, region, city

mozvpn.mozvpn.find_vpn_server_locations(wg_config_files: List[str])[source]

Find geographic locations of wireguard VPN server endpoints.

Parameters

wg_config_files – list of wireguard config files/directories

Returns

list of dictionaries containing configuration/location data.

mozvpn.mozvpn_gui module

mozvpn.wireguard module

Functions for interacting with wireguard command line tools.

exception mozvpn.wireguard.CommandError(msg, cmd)[source]

Bases: Exception

property msg
exception mozvpn.wireguard.ControlledExit[source]

Bases: Exception

Raise when error handling is finished and program can gracefully exit.

exception mozvpn.wireguard.WireguardError[source]

Bases: Exception

Raised when external wireguard or wg-quick command reported an error.

mozvpn.wireguard.check_wireguard_commands()dict[source]
Check absolute path to ‘wg’ and ‘wg-quick’ commands if they are installed

and executable.

Returns

‘/usr/bin/wg’, ‘wg-quick’: ‘/usr/bin/wg-quick’}

Return type

{‘wg’

Raises

RuntimeError if path to wireguard command could not be determined.

mozvpn.wireguard.connect(conf_or_if: str)[source]

Establish connection to VPN server via wg-quick command.

Parameters

conf_or_if

Either - Name of wireguard conf file, e.g. “/path/to/us122-wireguard.conf” - Name of wireguard interface, e.g. “us122-wireguard”

In this case the corresponding configuration file has to exist in the /etc/wireguard/ directory.

mozvpn.wireguard.disconnect(conf_or_if: str)[source]

Shut down connection to VPN server via wg-quick command.

Parameters

conf_or_if

Either - Path to wireguard conf file, e.g. “/path/to/us122-wireguard.conf” - Name of wireguard interface, e.g. “us122-wireguard”

In this case the corresponding configuration file has to exist at /etc/wireguard/INTERFACE.conf.

mozvpn.wireguard.interface()str[source]

Return interface of VPN connection, if available.

Returns

Name of connected interface (e.g. ‘de12-wireguard), otherwise None, if not connected.

mozvpn.wireguard.ipinfo()[source]

Obtain externally visible IP information from https://ipinfo.io

Returns: JSON like
{

“ip”: “185.213.155.160”, “city”: “Frankfurt am Main”, “region”: “Hesse”, “country”: “DE”, “loc”: “50.1155,8.6842”, “org”: “AS39351 31173 Services AB”, “postal”: “60311”, “timezone”: “Europe/Berlin”, “readme”: “https://ipinfo.io/missingauth

}

mozvpn.wireguard.mullvad_info()[source]

Obtain externally visible IP information from https://am.i.mullvad.net/json

Note: Mullvad is the provider behind MozillaVPN.

Returns: JSON like
{

“ip”: “212.14.256.33”, “country”: “Germany”, “city”: “Stadt”, “longitude”: 8.2, “latitude”: 44.4, “mullvad_exit_ip”: false, “blacklisted”: { … }, “organization”: “Telecom”

}

mozvpn.wireguard.run_command(cmd: str, shell: bool = False, verbose: bool = False, dry_run: bool = False)str[source]

Run external command, and collect results or errors.

Parameters
  • cmd – The command to be executed

  • shell – if True run command via shell.

  • verbose – if True print command to stdout.

  • dry_run – if True then the commands will only be written to stdout only. and not executed.

Raises

CommandError in case of failling command execution.

mozvpn.wireguard.setup_wireguard_configuration(user: str, verbose: bool, dry_run: bool, limit: int)[source]

Setup configurations needed to operate wireguard.

Parameters
  • user – name of primary user who should be allowed to use MozVPN.

  • verbose – if True print command to stdout.

  • dry_run – if True then the commands will only be written to stdout only.

  • limit – Limit the number of servers downloaded via mozwire and not executed.

mozvpn.wireguard.status(ip: bool = False)str[source]

Show status of VPN connection.

Parameters

ip – if given add currenlty visible external IP address to connection status.

Returns

String telling if VPN connection is up, and if so, which server is currently is used. The IP address will optionally be added. Examples: - ‘Not connected’ - ‘Connected to de10-wireguard’ - ‘Connected to de10-wireguard, ip: 234.12.642.0’

Module contents

Top-level package for mozvpn.