-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimrelay.py
executable file
·63 lines (60 loc) · 1.38 KB
/
simrelay.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
#!/usr/bin/python
import socket
import httplib
import urllib
import re
C_PORT = 45988 #Port used by telemetry unit
C_ADDR = None
S_PORT = 80 #Port used to connect to the webserver
S_ADDR = "81.167.78.33" #Server address
PATH = "/ecomarathon/setdata.php"
for res in socket.getaddrinfo(C_ADDR, C_PORT, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
print(res)
c_f, c_st, c_p, c_cn, c_sa = res
c_srv_soc = socket.socket(c_f, c_st, c_p)
c_srv_soc.bind(c_sa)
c_srv_soc.listen(1)
break
data = ""
while 1:
try:
car_soc, addr = c_srv_soc.accept()
except KeyboardInterrupt:
c_srv_soc.close()
break
except:
c_srv_soc.close()
continue
car_soc.settimeout(20.0);
try:
while 1:
data = ""
temp = ""
while not re.search("\n", data):
temp = car_soc.recv(1024)
data += temp
if not temp:
data = ""
break
if not data:
print("no data")
car_soc.close()
break
else:
print(data)
print("got some\n")
h1 = httplib.HTTPConnection(S_ADDR, S_PORT)
h1.request("POST", PATH, urllib.urlencode({"data": data}), {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
response = h1.getresponse()
print(response)
if response.status != 200:
print("http error")
break
data = response.read()
data = ""
h1.close
car_soc.close()
except:
car_soc.close()
continue
c_srv_soc.close()