Skip to content

Instantly share code, notes, and snippets.

@yonderbread
Last active May 22, 2021 05:12
Show Gist options
  • Select an option

  • Save yonderbread/bee9be0e4745d26987fe315d76305b60 to your computer and use it in GitHub Desktop.

Select an option

Save yonderbread/bee9be0e4745d26987fe315d76305b60 to your computer and use it in GitHub Desktop.
import requests
MULLVAD_ID = ""
def get_token(mullvad_id: str):
with requests.post(f"https://api.mullvad.net/www/accounts/{MULLVAD_ID}",
headers={
"Host": "api.mullvad.net",
"Origin": "https://api.mullvad.net",
"Referer": "https://mullvad.net/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0",
"Accept": "application/json",
"Connection": "keep-alive",
"Accept-Language": "en-US"
}) as req:
return req.json()["auth_token"]
def get_account(token: str):
with requests.get("https://api.mullvad.net/www/me",
headers={
"Authorization": f"Token {token}",
"Host": "api.mullvad.net",
"Origin": "https://mullvad.net",
"Referer": "https://mullvad.net/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0",
"Accept": "application/json",
"Connection": "keep-alive",
"Accept-Language": "en-US"
}) as req:
return req.json()
def delete_wg_key(token: str, pubkey: str):
with requests.post("https://api.mullvad.net/www/wg-pubkeys/revoke/",
headers={
"Authorization": f"Token {token}",
"Host": "api.mullvad.net",
"Origin": "https://mullvad.net",
"Referer": "https://mullvad.net/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0",
"Accept": "application/json",
"Connection": "keep-alive",
"Accept-Language": "en-US",
"Content-Type": "application/json"
},
json={"pubkey": pubkey}) as req:
if req.status_code == 204:
print('Deleted pubkey: ' + pubkey)
return True
print('Failed to delete pubkey: ' + pubkey)
print('Status Code: ' + str(req.status_code))
print('Status Message: ' + req.content.decode('utf-8'))
return False
if __name__ == '__main__':
t = get_token(MULLVAD_ID)
print("Got token")
acc = get_account(t)
print("Logged in")
delc = 0
for peer in acc["account"]["wg_peers"]:
deleted = delete_wg_key(t, peer["key"]["public"])
if deleted:
delc += 1
print("Deleted " + str(delc) + " wireguard key(s).")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment