-
Notifications
You must be signed in to change notification settings - Fork 10
/
Api_request.py
102 lines (93 loc) · 2.34 KB
/
Api_request.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import requests
import json
import hashlib
from getpass import getpass
secret = None
address= '10.0.0.69:9877'
hashed = None
def get_ses():
global hashed
if secret is None:
print("You need to enter the secret first")
return False
else:
r = requests.get("http://"+address+"/ses")
print(r.status_code, r.reason)
b = json.loads(r.text)
#print(b['data'])
ses = b['data']
hashed = hashlib.sha512(str(ses).encode('utf-8')+str(secret).encode('utf-8')).hexdigest()
return True
def get_status():
r = requests.get("http://"+address+"/")
print(r.status_code, r.reason)
try:
b = json.loads(r.text)
print(b)
except:
print("no json")
def turn_on():
if get_ses():
#print(hashed)
r = requests.post("http://"+address+"/start", data={'data': hashed})
print(r.status_code, r.reason)
try:
b = json.loads(r.text)
print(b)
except:
print("no json")
else:
print("failed to get session")
def turn_off():
if get_ses():
#print(hashed)
r = requests.post("http://"+address+"/stop", data={'data': hashed})
print(r.status_code, r.reason)
try:
b = json.loads(r.text)
print(b)
except:
print("no json")
else:
print("failed to get session")
def restart():
if get_ses():
#print(hashed)
r = requests.post("http://"+address+"/restart", data={'data': hashed})
print(r.status_code, r.reason)
try:
b = json.loads(r.text)
print(b)
except:
print("no json")
else:
print("failed to get session")
def print_menu():
print(30 * "-" , "MENU" , 30 * "-")
print("1. Start")
print("2. Stop")
print("3. Enter secret")
print("4. get status")
print("5. restart")
print("6. Exit")
print(67 * "-")
loop=True
while loop:
print_menu()
choice = input("Enter your choice [1-6]: ")
print("\n"*5)
if choice=='1':
turn_on()
elif choice=='2':
turn_off()
elif choice=='3':
secret = getpass()
elif choice=='4':
get_status()
elif choice=='5':
restart()
elif choice=='6':
exit(0)
else:
print("wrong input")
print("\n"*5)