Skip to content

Commit

Permalink
Get ip address from login buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
dashroshan authored Dec 11, 2021
1 parent afb465d commit 5076603
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions clashapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import requests
from base64 import b64decode as base64_b64decode
from json import loads as json_loads

def updatekeys(email, password, baseUrl, scopes):
#Getting the current ip address of the system
currentIP=requests.get("https://api.ipify.org").content.decode('utf8')

#Creating a session
session=requests.Session()

#Loggin in
session.post(url=f"{baseUrl}/api/login", json={"email": email,"password": password})
loginData=session.post(url=f"{baseUrl}/api/login", json={"email": email,"password": password})

#Getting the current ip address of the system from the buffer returned by the login post. api.ipify.org is used as a fallback.
try:
currentIP=json_loads(base64_b64decode(loginData.json()["temporaryAPIToken"].split(".")[1]+"=").decode("utf-8"))["limits"][1]["cidrs"][0].split("/")[0]
except:
currentIP=requests.get("https://api.ipify.org").content.decode('utf8')

#Getting the list of current keys
#If the ip address of a key is not the current one, its id, name, and description is added to the KeysToUpdate list
Expand Down Expand Up @@ -42,4 +47,4 @@ def coc(email, password):


def cr(email, password):
return updatekeys(email,password,"https://developer.clashroyale.com","royale")
return updatekeys(email,password,"https://developer.clashroyale.com","royale")

0 comments on commit 5076603

Please sign in to comment.