22from __future__ import absolute_import , division , print_function
33import settings
44import time
5+ import netifaces
6+ import json
57
68SERVER = 'http://' + settings .BADGE_SERVER_ADDR + ':' + settings .BADGE_SERVER_PORT + '/'
79PROJECTS_ENDPOINT = '{}projects' .format (SERVER )
1012BEACONS_ENDPOINT = '{}beacons/' .format (SERVER )
1113DATAFILES_ENDPOINT = "{}{}" .format (SERVER , "{}/datafiles" )
1214
15+
1316def _badge (x ):
1417 """
1518 Generates endpoint for a given badge
@@ -35,6 +38,7 @@ def _hub(x):
3538 """
3639 return '{}{}/' .format (HUBS_ENDPOINT , x )
3740
41+
3842def _data (x ):
3943 """
4044 Generates endpoint for a given hub
@@ -48,13 +52,35 @@ def _data(x):
4852DATA_ENDPOINT = _data
4953HUB_ENDPOINT = _hub
5054
55+
56+ def get_ips ():
57+ """
58+ Generates a JSON string with the list of IPs used by the hub
59+ :return:
60+ """
61+ interfaces = netifaces .interfaces ()
62+ ips = []
63+ for i in interfaces :
64+ if i == 'lo' :
65+ continue
66+ iface = netifaces .ifaddresses (i ).get (netifaces .AF_INET )
67+ if iface is not None :
68+ for j in iface :
69+ ips .append ({i :j ['addr' ]})
70+
71+ ips_json = json .dumps (ips )
72+ return ips_json
73+
74+
5175def request_headers ():
5276 """
5377 Generate the headers to be used for all requests to server
5478 Note - all items must be strings
5579 """
80+ print (get_ips ())
5681 return {
5782 "X-APPKEY" : settings .APPKEY ,
5883 "X-HUB-UUID" : settings .HUB_UUID ,
59- "X-HUB-TIME" : str (time .time ())
84+ "X-HUB-TIME" : str (time .time ()),
85+ "X-ALL-IPS" : get_ips ()
6086 }
0 commit comments