-
Notifications
You must be signed in to change notification settings - Fork 3
/
login.py
71 lines (53 loc) · 2.02 KB
/
login.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import base64
import hashlib
import string
import random
import requests
import time
def rand_gen(size, chars=string.ascii_lowercase + string.digits):
return str(''.join(random.choice(chars) for _ in range(size)))
def msg_id(unix_time):
concat_string = '{}{}'.format(rand_gen(16), unix_time)
final_md5 = hashlib.md5(concat_string.encode('utf-8')).hexdigest()
return str(final_md5)
def get_unix_time():
current_time = int(time.time())
return current_time
def get_key(username, password, uts):
nonce = rand_gen
unix_time = uts
param = '{{"email":"{}","password":"{}"}}'.format(username, password)
encoded_param = base64.standard_b64encode(param.encode('utf8'))
concat_sign = '{}{}{}{}'.format('23x17ahWarFH6w29', unix_time, nonce, encoded_param.decode("utf-8"))
sign = hashlib.md5(concat_sign.encode('utf-8')).hexdigest()
headers = {
'content-type': 'application/x-www-form-urlencoded',
}
data = {
'params': encoded_param,
'sign': sign,
'timestamp': unix_time,
'nonce': nonce
}
response = requests.post('https://iot.meross.com/v1/Auth/login', headers=headers, data=data)
key = response.json()['data']['key']
userid = response.json()['data']['userid']
token = response.json()['data']['token']
return str(key), str(userid), str(token)
def signing_key(message_id, key, uts):
concat_string = '{}{}{}'.format(message_id, key, uts)
final_md5 = hashlib.md5(concat_string.encode('utf-8')).hexdigest()
return str(final_md5)
def login(username, password):
current = get_unix_time()
message_id = msg_id(current)
key, userid, token = get_key(username, password, current)
sign = signing_key(message_id,key, current)
print("{} {}".format("userId:", userid))
print("{} {}".format("key:", key))
print("{} {}".format("token:", token))
print("{} {}".format("messageId:", message_id))
print("{} {}".format("sign:", sign))
print("{} {}".format("timestamp:", current))
#ONLY MODIFY THIS
login("<email>", "<password>")