import sys, glob, json, os # Find config.json under /routlin_location config_path = None for candidate in [ '/routlin_location/config.json', '/routlin_location/configs/config.json', ]: if os.path.exists(candidate): config_path = candidate break if not config_path: matches = glob.glob('/routlin_location/**/config.json', recursive=True) config_path = matches[0] if matches else None if not config_path: print('ERROR: could not find config.json under /routlin_location') sys.exit(1) print(f'Using config: {config_path}') cfg = json.load(open(config_path)) res = {r['mac'].lower(): r['hostname'] for r in cfg.get('dhcp_reservations', []) if r.get('mac') and r.get('hostname')} print(f'{len(res)} reservations in mac_to_res') for f in sorted(glob.glob('/var/lib/misc/dnsmasq-routlin-*.leases')): print(f'\n--- {f} ---') for line in open(f): p = line.strip().split() if len(p) >= 4: mac = p[1].lower() device_h = p[3] if p[3] != '*' else '(none)' res_h = res.get(mac, '(no reservation)') print(f' mac={mac} device_h={device_h} res_h={res_h}') try: from mac_vendor_lookup import MacLookup ml = MacLookup() print('\n--- vendor lookup test ---') for mac in list(res.keys())[:5]: try: vendor = ml.lookup(mac) except Exception as e: vendor = f'(error: {e})' print(f' {mac} {vendor}') except ImportError: print('\nmac-vendor-lookup not installed')