-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoapclient.py
27 lines (26 loc) · 1.36 KB
/
coapclient.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
from aiocoap import *
class CoapClient:
def __init__(self, peer):
self.peer = peer
self.remote = []
for x in range(len(peer.info) / 2):
endpoint = {}
endpoint['type'] = peer.info[2 * x]
if t == 1:
arr = peer.info[2 * x + 1]
endpoint['port'] = int.from_bytes(arr[0:1],'big')
endpoint['addr'] = str(int.from_bytes(arr[2],'big')) + '.' +
str(int.from_bytes(arr[3],'big')) + '.' +
str(int.from_bytes(arr[4],'big')) + '.' +
str(int.from_bytes(arr[5],'big'))
elif t == 2:
arr = peer.info[2 * x + 1]
endpoint['port'] = int.from_bytes(arr[0:1],'big')
endpoint['addr'] = '{4x}'.format(arr[2:3],'big') + ':' +
'{4x}'.format(arr[4:5],'big') + ':' +
'{4x}'.format(arr[6:7],'big') + ':' +
'{4x}'.format(arr[8:9],'big') + ':' +
'{4x}'.format(arr[10:11],'big') + ':' +
'{4x}'.format(arr[12:13],'big') + ':' +
'{4x}'.format(arr[14:15],'big') + ':' +
'{4x}'.format(arr[16:17],'big')