Last active
January 17, 2019 08:55
-
-
Save MaxLevs/151161cbb9f4f55e3efbff569702d94f to your computer and use it in GitHub Desktop.
Check available for Minecraft account.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import requests | |
import json | |
import argparse | |
from sys import exit | |
import uuid | |
client_token = str(uuid.uuid4()) | |
def parse_arguments(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-u', '--username', | |
required=True, | |
help="Login or Email") | |
parser.add_argument('-p', '--password', | |
required=True, | |
help="User passwod") | |
args = parser.parse_args() | |
return args | |
class MC_Request(): | |
base_url = "https://authserver.mojang.com" | |
endpoint = None | |
headers = {"Content-Type": "application/json"} | |
data = None | |
last_responce = None | |
def __init__(self, endpoint="/"): | |
if type(endpoint) != str or endpoint[0] != "/": | |
raise ValueError("Endpoint must be string started with '/'") | |
self.endpoint = endpoint | |
def url(self): | |
return self.base_url + self.endpoint | |
def set_data(self, data): | |
if type(data) != dict: | |
raise ValueError("Data must be dict") | |
self.data = data | |
def send_req(self): | |
self.last_responce = requests.post(self.url(), | |
headers=self.headers, | |
data=json.dumps(self.data)) | |
return self.last_responce | |
def analise_responce(self): | |
pass | |
class MC_LogIn(MC_Request): | |
def __init__(self, username, password): | |
super().__init__(endpoint="/authenticate") | |
if type(username) != str or type(password) != str: | |
raise ValueError("Username and Password must be string") | |
self.data = { | |
"agent": {"name": "Minecraft", "version": 1}, | |
"username": username, | |
"password": password, | |
"clientToken": globals()["client_token"], | |
"requestUser": True | |
} | |
class MC_LogOut(MC_Request): | |
def __init__(self, username, password): | |
super().__init__(endpoint="/signout") | |
if type(username) != str or type(password) != str: | |
raise ValueError("Username and Password must be string") | |
self.data = { | |
"username": username, | |
"password": password, | |
} | |
class MC_Invalidate(MC_Request): | |
def __init__(self, access_token): | |
super().__init__(endpoint="/invalidate") | |
if type(access_token) != str: | |
raise ValueError("AccessToken must be string") | |
self.data = { | |
"accessToken": access_token, | |
"clientToken": globals()["client_token"], | |
} | |
def analise_responce(self): | |
ans = {"exit_code": None, "text": None} | |
if self.last_responce.status_code == 203: | |
ans["exit_code"] = 0 | |
ans["text"] = "Test_Token deleted!" | |
else: | |
ans["exit_code"] = 3 | |
ans["text"] = "Test_Token cannot die!" | |
return ans | |
class Verify_Login(MC_LogIn): | |
def analise_responce(self): | |
ans = {"exit_code": None, "text": None} | |
if self.last_responce.status_code == 200: | |
profile_data = json.loads(self.last_responce.text)[ | |
"selectedProfile"] | |
ans["exit_code"] = 0 | |
ans["text"] = "Result: [%d] You are loged in as %s" % ( | |
self.last_responce.status_code, | |
profile_data["name"]) | |
elif self.last_responce.status_code == 403: | |
ans["exit_code"] = 1 | |
ans["text"] = "Result: [%d] Invalid username or password" % self.last_responce.status_code | |
else: | |
ans["exit_code"] = 2 | |
ans["text"] = "Something wrong! Check your code!" | |
return ans | |
def main(): | |
args = parse_arguments() | |
print("Check login for %s" % (args.username)) | |
verify_login = Verify_Login(args.username, args.password) | |
res = verify_login.send_req().text | |
res = json.loads(res) | |
ans = verify_login.analise_responce() | |
print(ans["text"]) | |
print("Delete accessToken") | |
invalidate = MC_Invalidate(res["accessToken"]) | |
invalidate.send_req() | |
print(invalidate.analise_responce()["text"]) | |
exit(ans["exit_code"]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment