A fully-fledged Mullvad wrapper for Python.
This is a 2-hours project so expect bugs, random code and ghosts waking you up at night 1.
Most methods just rely on standard Mullvad APIs (I used this bash script as inspiration https://mullvad.net/media/files/mullvad-wg.sh).
This should cover generic use-cases such as: config generation, key uploading, key revoking, account info, relays list, etc etc
Only requirement is Python 3.X and wireguard for key generation (https://www.wireguard.com/install/).
Let me know if something doesn't work for you. PRs are very welcome.
mullvad = MullvadAPI(ACCOUNT_NUMBER)
relays = mullvad._list_relays_json()
for country in relays['countries']:
print('\n= %s [ %s ] =' % (country['name'], country['code']))
for city in country['cities']:
print('%s [ %s ]' % (city['name'], city['code']))
for relay in city['relays']:
print('\t----> %s [ %s ]' % (relay['hostname'], relay['ipv4_addr_in']))
print('There are %d countries listed on MullVad' % len(relays['countries']))
mullvad.is_vpn_connected()
mullvad.get_relay('us58-wireguard')
mullvad.generate_pkey()
mullvad._derivatePubKey(PRIVATE_KEY)
mullvad.add_pubkey(PUBLIC_KEY)
- Mullvad API will get an authorization token for you, using your account number and then revoke the relevant key
mullvad.revoke_pubkey(PUBLIC_KEY)
res = mullvad.generate_conf(hostname='us58-wireguard')
res = mullvad.generate_conf(hostname='us58-wireguard', private_key = private_key)
print(res['config'])
Footnotes
-
Yes, ghosts are real ↩