This repository has been archived by the owner on Jul 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_sender.py
82 lines (56 loc) · 1.42 KB
/
cmd_sender.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
#Imports
#import socket
#import sys
#Static vars
#HOST = socket.gethostname()#'127.0.0.1'
#PORT = 10000
#Attempt connection
#try:
#s = socket.socket()
#s.connect((HOST, PORT))
#if len(sys.argv) > 1:
#print "args:", str(sys.argv)
#s.send(" ".join(sys.argv[1:]))
#else:
#while 1:
#msg = raw_input("Command to Send: ")
#Send command to hub
#s.send(msg)
#Close if close message
#if msg == "close":
#s.close()
#sys.exit(0)
#except Exception:
#print "Connection could not be established."
import requests
import sys
PORT = "5000"
data = {} # Set POST fields here
def send(cmddict):
#Request
#params = urllib.urlencode(data)
#headers = {"Content-type": "application/x-www-form-urlencoded"}
#httpServ = http.client.HTTPConnection(HOST + ":" + PORT)
#httpServ.request("POST", "", params, headers)
#Response
#response = httpServ.getresponse()
#print(" -> " + response.read())
#httpServ.close()
r = requests.post("http://"+ "192.168.1.72" + ":" + PORT, data=cmddict, timeout=5)
print(" -> " + r.text)
if len(sys.argv) > 2:
print("args:", str(sys.argv))
data["auth"] = sys.argv[1]
data["command"] = " ".join(sys.argv[2:])
send(data)
else:
HOST = input("HUB IP <- ")
auth = input("AUTHORIZATION <- ")
while 1:
try:
#Send command to hub
data["auth"] = auth
data["command"] = input("HUB <- ")
send(data)
except Exception as e:
print ("Coult not reach HUB")