A complete api for mullvad.net
Project description
mullvad-api
A complete api for mullvad.net
Installation
pip install mullvad-neo-api
Usage
CLI
usage: python -m mullvadapi [-h] [-p PASSWORD] [-w TIME] [-W TIME] [-r NUM] [--retry-delay TIME] [--retry-all-errors] [-m TIMEOUT] [-k] [-L] [--max-redirs NUM] [-A UA]
[-x PROXY] [-H HEADER] [-b COOKIE] [-B BROWSER]
{create-account,status,devices,instances,version,create-device,revoke-device,receipt,create-config} ...
Tool for interacting with mullvad.net
If password is not passed through arguments, it'll be read from $MULLVAD_PASSWORD environment variable.
General:
-h, --help Show this help message and exit
-p, --password PASSWORD
Specify password for authentication
subcommands:
{create-account,status,devices,instances,version,create-device,revoke-device,receipt,create-config}
create-account create account
status Get status
devices Get devices
instances Get instances
version Get version
create-device create new device
revoke-device remove device
receipt Get receipt
create-config create wireguird config
Request settings:
-w, --wait TIME Set waiting time for each request
-W, --wait-random TIME
Set random waiting time for each request to be from 0 to TIME
-r, --retry NUM Set number of retries for failed request to NUM
--retry-delay TIME Set interval between each retry
--retry-all-errors Retry no matter the error
-m, --timeout TIMEOUT
Set request timeout, if in TIME format it'll be set for the whole request. If in TIME,TIME format first TIME will specify connection timeout, the
second read timeout. If set to '-' timeout is disabled
-k, --insecure Ignore ssl errors
-L, --location Allow for redirections, can be dangerous if credentials are passed in headers
--max-redirs NUM Set the maximum number of redirections to follow
-A, --user-agent UA Sets custom user agent
-x, --proxy PROXY Use the specified proxy, can be used multiple times. If set to URL it'll be used for all protocols, if in PROTOCOL URL format it'll be set only for
given protocol, if in URL URL format it'll be set only for given path. If first character is '@' then proxies are read from file
-H, --header HEADER Set curl style header, can be used multiple times e.g. -H 'User: Admin' -H 'Pass: 12345', if first character is '@' then headers are read from file
e.g. -H @file
-b, --cookie COOKIE Set curl style cookie, can be used multiple times e.g. -b 'auth=8f82ab' -b 'PHPSESSID=qw3r8an829', without '=' character argument is read as a file
-B, --browser BROWSER
Get cookies from specified browser e.g. -B firefox
Password for login can be specified either by options or in MULLVAD_PASSWORD environment variable.
mullvadapi -p 1234567890123456 status
export MULLVAD_PASSWORD='1234567890123456'
mullvadapi status
Additional options for requests also can be specified before the subcommand
mullvadapi --wait 0.1 -header 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0' status
create-account
mullvadapi create-account
Creates new account and prints it's password
status
mullvadapi status
Prints general status of the account in json
instances
mullvadapi instances
Prints a list of all server instances available in json
devices
mullvadapi devices
Prints info about currently registered devices in json
version
mullvadapi version
Prints version string of mullvad
create-device
mullvadapi create-device <PUBKEY>
Registers new device with specified wireguard public key and prints info about it in json
revoke-device
mullvadapi revoke-device <UUID>
Removes device by it's uuid
receipt
mullvadapi receipt <SOURCE> <TOKEN>
Prints info about receipt in json by it's token, source can be swish, paypal, card or other.
create-config
mullvadapi create-config <INSTANCE> <DEVICE>
Prints wireguard config file by extracting info from instance and device info passed as json, extracted from output of instances and devices subcommands.
Library
Code
from mullvadapi import Api, Error, RequestError, AuthorizationError, FailedError
password='1234567890123456'
try:
api = Api(password)
except AuthorizationError:
print(f"Invalid password - {password}")
exit(1)
except RequestError as e:
print("request error - {}".format(repr(e)))
exit(1)
if len(api.status()['me']['expiry']) == 0:
print("No time left on the account")
exit(1)
try:
devices = api.devices()
instances = api.instances()
except Error as e:
print(repr(e))
device = None
if len(devices) == 0:
wireguard_pubkey="rWiQxq5lAWD8v/bws9ITSAvThyZW8cR2x+Ins9ZvvRo="
device = api.create_device(wireguard_pubkey)
else:
device = devices[0]
#creates wireguard config
print(api.create_config(instances[0],device))
Api
Api class provides methods for interacting with mullvad.net, at it's initialization password can be passed which will be passed to login method, it also accepts parameters for treerequests session.
login(self, password: str)
Log in to account
logout(self)
Log out from account
receipt(self, source: str, token: str) -> dict
Get receipt on transaction, source can be swish, paypal, card or other.
status_raw(self) -> dict
Get status of user
status(self) -> dict
Get status of user in format easier to use
devices_raw(self) -> dict:
List devices of user
devices(self) -> dict:
List devices of user in format easier to use
create_device(self, key: str) -> dict
Create a new device with wireguard public key.
On error raises FailedError, otherwise format similar to devices method is returned about the newly created device.
revoke_device(self, uuid: str) -> bool
Remove device with uuid.
Returns True on success and False on failure.
version(self) -> str
Get version string
create_account(self) -> str
Create new account and return password.
FailedError is raised on failure
create_config(self, instance: dict, device: dict) -> str
Creates wireguard configuration from instance and device which should bee derived from instances and devices methods
instances(self) -> List[dict]
Gets full list of available server instances
Exceptions
All exceptions raised by this library are derived from Error.
RequestError is raised for errors when handling requests.
AuthenticationError is raised by calling methods needing authentication without being logged in.
FailedError is raised by create_device and create_user methods on failure.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mullvad_neo_api-0.0.1.tar.gz.
File metadata
- Download URL: mullvad_neo_api-0.0.1.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
626dc18218342bc52883ad07e3491efe55e4675d864549ba30d0f05f5d1e567b
|
|
| MD5 |
e91cb15721d9dc4ffaae0a3d7a82ca9c
|
|
| BLAKE2b-256 |
60c73381719c5d3a35f336dabbf94777baeae4ac8eb6c16523b47fbe5020344e
|
File details
Details for the file mullvad_neo_api-0.0.1-py3-none-any.whl.
File metadata
- Download URL: mullvad_neo_api-0.0.1-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
435b2dbc6745d06825133cbbf6e1195f423ab843150ccd6e45d1c7a6099339f9
|
|
| MD5 |
15da53f01617841f19c87ef715c2fed2
|
|
| BLAKE2b-256 |
8760aec49c48ab5c6f5af0450d49e548ad7fdbbfd7c59de12a7ef6b117f52719
|