Development
This commit is contained in:
parent
375bf108cc
commit
09e6b7403d
3 changed files with 53 additions and 6 deletions
47
debug_leases.py
Normal file
47
debug_leases.py
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
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')
|
||||||
|
|
@ -17,16 +17,16 @@ HEALTH_FILE = os.path.join(CONFIGS_DIR, '.health')
|
||||||
bp = Blueprint('view_page', __name__)
|
bp = Blueprint('view_page', __name__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import manuf as _manuf_mod
|
from mac_vendor_lookup import MacLookup as _MacLookup
|
||||||
_mac_parser = _manuf_mod.MacParser()
|
_mac_lookup = _MacLookup()
|
||||||
except Exception:
|
except Exception:
|
||||||
_mac_parser = None
|
_mac_lookup = None
|
||||||
|
|
||||||
def _get_vendor(mac):
|
def _get_vendor(mac):
|
||||||
if _mac_parser is None:
|
if _mac_lookup is None:
|
||||||
return ''
|
return ''
|
||||||
try:
|
try:
|
||||||
return _mac_parser.get_comment(mac) or _mac_parser.get_manuf(mac) or ''
|
return _mac_lookup.lookup(mac) or ''
|
||||||
except Exception:
|
except Exception:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
flask
|
flask
|
||||||
bcrypt
|
bcrypt
|
||||||
manuf
|
mac-vendor-lookup
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue