# credits: https://gist.github.com/calebmadrigal/fdb8855a6d05c87bbb0254a1424ee582 import sys import yaml import requests import json import hmac import hashlib IDENTITIES_URL = "http://localhost:8080/identities.json" WEBHOOK_URL = "http://localhost:8080/update.php" WEBHOOK_SECRET = "CHANGE-THIS" def get_identities(): resp = requests.get(IDENTITIES_URL) return resp.json() def parse_wifi_map(map_path): # read scan results with open(map_path, 'r') as f: wifi_map = yaml.safe_load(f) # read known identities identities = get_identities() print("Known identities:") for identity in identities: print('mac hash = {}, name = {}'.format(identity['mac_hash'],identity['name'])) filtered_identities = set() # filter scan results for known identities for ssid in wifi_map: ssid_node = wifi_map[ssid] for bssid in ssid_node: bssid_node = ssid_node[bssid] if 'devices' in bssid_node: for device in bssid_node['devices']: for identity in identities: mac_hash = hashlib.sha256(device.encode()).hexdigest() if identity['mac_hash'] == mac_hash: filtered_identities |= {identity['name']} print('\nFiltered identities:') print(filtered_identities) return filtered_identities if __name__ == '__main__': wifi_map_path = 'wifi_map.yaml' if len(sys.argv) > 1: wifi_map_path = sys.argv[1] filtered_identities = parse_wifi_map(wifi_map_path) # build request json_payload = json.dumps(list(filtered_identities)).encode("utf-8") signature = hmac.new( key=bytes(WEBHOOK_SECRET, "utf-8"), msg=json_payload, digestmod=hashlib.sha256 ).hexdigest() req_headers = { 'Content-Type': 'application/json', 'x-hmac-hash': signature } # send request r = requests.post(url=WEBHOOK_URL, data=json_payload, headers=req_headers) print("Upload response:") print(r.status_code)