2014-01-24 02:53:17 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
|
|
|
|
class alfred:
|
|
|
|
def __init__(self,request_data_type = 158):
|
|
|
|
self.request_data_type = request_data_type
|
|
|
|
|
|
|
|
def aliases(self):
|
2014-07-05 20:23:06 +02:00
|
|
|
output = subprocess.check_output(["alfred-json","-r",str(self.request_data_type),"-f","json","-z"])
|
2014-01-24 02:53:17 +01:00
|
|
|
alfred_data = json.loads(output.decode("utf-8"))
|
|
|
|
alias = {}
|
|
|
|
for mac,node in alfred_data.items():
|
|
|
|
node_alias = {}
|
|
|
|
if 'location' in node:
|
2014-03-30 13:19:54 +02:00
|
|
|
try:
|
|
|
|
node_alias['gps'] = str(node['location']['latitude']) + ' ' + str(node['location']['longitude'])
|
|
|
|
except:
|
|
|
|
pass
|
2014-02-02 23:28:09 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
node_alias['firmware'] = node['software']['firmware']['release']
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
2014-05-02 10:49:01 +02:00
|
|
|
try:
|
|
|
|
node_alias['id'] = node['network']['mac']
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
2014-01-24 02:53:17 +01:00
|
|
|
if 'hostname' in node:
|
|
|
|
node_alias['name'] = node['hostname']
|
|
|
|
elif 'name' in node:
|
|
|
|
node_alias['name'] = node['name']
|
|
|
|
if len(node_alias):
|
|
|
|
alias[mac] = node_alias
|
|
|
|
return alias
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
ad = alfred()
|
2014-05-31 14:53:28 +02:00
|
|
|
al = ad.aliases()
|
2014-01-24 02:53:17 +01:00
|
|
|
print(al)
|