-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweaved.py
96 lines (65 loc) · 2.49 KB
/
weaved.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
import json, requests, sys, getpass, os
def Init():
print("+===== Weaved CLI - Mike Resoli (c) =====+")
print("")
print("")
try:
username = input("Enter your email address: ")
password = getpass.getpass()
url = "https://api.weaved.com/v22/api/user/login/" + username + "/" + password
print("Connecting...")
loginData = requests.get(url, headers={"apikey":"WeavedDemoKey$2015"}, timeout=10);
loginJson = json.loads(loginData.text)
if loginJson['status'] == "true":
clearScreen()
token = loginJson['token']
getDevices(token)
else:
print("Error 1: Unable to connect to api.weaved.com. Check your credentials.")
sys.exit()
except SyntaxError:
print("Wrap your email address in double quotes.")
Init()
def getDevices(token):
url = "https://api.weaved.com/v22/api/device/list/all"
print("Retrieving devices using token " + token)
deviceData = requests.get(url, headers={"apikey":"WeavedDemoKey$2015","token":token}, timeout=10);
deviceJson = json.loads(deviceData.text)
if deviceJson['status'] == "true":
listDevices(deviceJson, token)
else:
print("Error 2: There was a problem retrieving the device list");
sys.exit()
def listDevices(json, token):
print("Listing devices...")
print("")
print("+===== Devices =====+")
for i in json['devices']:
print(i['devicealias'] + " || " + i['devicestate'])
print("")
picked = int(input("Select a device (enter 0 for the first): "))
clearScreen()
try:
deviceAddress = json['devices'][picked]['deviceaddress']
deviceIp = json['devices'][picked]['devicelastip']
print("Getting connection info for " + json['devices'][picked]['devicealias'])
getConnectionInfo(deviceAddress, deviceIp, token)
except:
print("Your selection is out of range.")
print("")
listDevices(json, token)
def getConnectionInfo(deviceAddress, hostIp, token):
url = "https://api.weaved.com/v22/api/device/connect"
connectionData = requests.post(url, headers={"apikey":"WeavedDemoKey$2015","token":token}, json={"deviceaddress":deviceAddress,"hostip":hostIp,"wait":"true"}, timeout=20);
connectionJson = json.loads(connectionData.text)
if connectionJson['status'] == "true":
print("")
print("Connection: " + connectionJson['connection']['proxy'])
else:
print("Error 3: There was a problem getting the connection details.")
def clearScreen():
if (os.name in ('ce', 'nt', 'dos')):
os.system('cls')
else:
os.system('clear')
Init()