Development
This commit is contained in:
parent
5a3a18d5b0
commit
99a4cf637f
2 changed files with 19 additions and 16 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import ipaddress
|
||||
import os
|
||||
import glob
|
||||
import subprocess
|
||||
from datetime import datetime, timezone
|
||||
from config_utils import collect_layout_tokens, load_config, relative_time
|
||||
from factory import (
|
||||
|
|
@ -47,29 +46,32 @@ def _vendor_cell(vendor):
|
|||
|
||||
|
||||
def _get_arp_table():
|
||||
"""Return {mac_lower: state} from `ip neigh`. Excludes FAILED/PERMANENT/INCOMPLETE."""
|
||||
"""Return {mac_lower: entry} from /proc/net/arp (host-mounted). ATF_COM (0x2) flag means
|
||||
the entry is complete; entries without it (incomplete) are excluded."""
|
||||
try:
|
||||
result = subprocess.run(['ip', 'neigh'], capture_output=True, text=True, timeout=5)
|
||||
entries = {}
|
||||
for line in result.stdout.splitlines():
|
||||
parts = line.split()
|
||||
if 'lladdr' not in parts:
|
||||
continue
|
||||
state = parts[-1]
|
||||
if state in ('FAILED', 'PERMANENT', 'NOARP', 'INCOMPLETE'):
|
||||
continue
|
||||
idx = parts.index('lladdr')
|
||||
mac = parts[idx + 1].lower()
|
||||
ip = parts[0]
|
||||
iface = parts[2] if len(parts) > 2 else ''
|
||||
entries[mac] = {'ip': ip, 'iface': iface, 'state': state}
|
||||
with open('/proc/net/arp') as f:
|
||||
next(f) # skip header line
|
||||
for line in f:
|
||||
parts = line.split()
|
||||
if len(parts) < 6:
|
||||
continue
|
||||
ip = parts[0]
|
||||
flags = int(parts[2], 16)
|
||||
mac = parts[3].lower()
|
||||
iface = parts[5]
|
||||
if not (flags & 0x2):
|
||||
continue
|
||||
if mac == '00:00:00:00:00:00':
|
||||
continue
|
||||
entries[mac] = {'ip': ip, 'iface': iface, 'state': 'REACHABLE'}
|
||||
return entries
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def _status_badge(state):
|
||||
if state == 'REACHABLE':
|
||||
if state:
|
||||
return '<span class="badge badge-enabled">Online</span>'
|
||||
return '<span class="badge badge-disabled">Offline</span>'
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ services:
|
|||
- /sys/devices:/sys/devices:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /var/lib/misc:/var/lib/misc:ro
|
||||
- /proc/net/arp:/proc/net/arp:ro
|
||||
- /var/log/freeradius:/var/log/freeradius
|
||||
environment:
|
||||
- PYTHONPATH=/routlin_location
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue