DHCP, ARP, and NDP
Timestamped host observations
To use get_host_observation_entries(), enable automatic host discovery on OPNsense
and grant the API user Interfaces: Neighbors: Automatic discovery.
Group observations from either address family by MAC and apply your own presence
window. Raw NDP entries alone do not prove current reachability.
API reference
- async OPNsenseClient.get_arp_table(resolve_hostnames=False)
Deprecated
Use get_arp_entries() instead; raw rows remain available as table.raw_rows.
Return raw ARP rows through the deprecated compatibility API.
Deprecated: use
get_arp_entries()for normalized entries and complete raw rows.
- async OPNsenseClient.get_ndp_table()
Deprecated
Use get_ndp_entries() instead; raw rows remain available as table.raw_rows.
Return raw NDP rows through the deprecated compatibility API.
Deprecated: use
get_ndp_entries()for normalized entries and complete raw rows.- Returns:
Unmodified rows, or None when unavailable or malformed.
- Return type:
list | None
- async OPNsenseClient.get_arp_entries(resolve_hostnames=False)
Return the active ARP table with normalized entries.
Fetches all rows in one POST request and normalizes them locally. A response whose
totaldoes not match the returned row count is treated as unavailable.- Parameters:
resolve_hostnames (bool) – Whether reverse DNS lookups should be requested.
- Returns:
- Normalized rows plus the count of rows that could not be
interpreted and isolated raw copies for diagnostics. None means the lookup was unavailable or malformed, as for
get_arp_table(); a successful empty table has no entries.
- Return type:
ArpNdpTable | None
- async OPNsenseClient.get_ndp_entries()
Return the IPv6 neighbor table with normalized entries.
Fetches all rows in one POST request and normalizes them locally. A response whose
totaldoes not match the returned row count is treated as unavailable.- Returns:
- Normalized rows plus the count of rows that could not be
interpreted and isolated raw copies for diagnostics. None means the lookup was unavailable or malformed, as for
get_ndp_table(); a successful empty table has no entries.
- Return type:
ArpNdpTable | None
- async OPNsenseClient.get_host_observations()
Deprecated
Use get_host_observation_entries() instead.
Return timestamped MAC observations as dictionaries for compatibility.
Deprecated: use
get_host_observation_entries()for immutable typed results.
- async OPNsenseClient.get_host_observation_entries()
Return validated host observations as immutable typed entries.
- Returns:
- Frozen normalized observations, including an empty
arp-ndpresult when host discovery is disabled. None means unavailable or malformed data. Each call sends at most one observation request; a fresh cached absent status can avoid the request.
- Return type:
HostObservations | None
- async OPNsenseClient.get_dhcp_leases(opnsense_tz=None)
Return active DHCP leases grouped by interface.
- Parameters:
opnsense_tz (tzinfo | None, optional) – Timezone used to localize ISC lease expiration timestamps. Fetched from OPNsense when omitted.
- Returns:
- Mapping with
lease_interfaceskeyed by interface name and
leaseskeyed by interface name. Lease entries are normalized across Kea, ISC, and dnsmasq and include address, hostname, interface, type, MAC, and expiration when available. Hostnames made only of dots are reported as None, like empty or missing hostnames.lease_interfacesalso lists interfaces that Kea DHCPv4 or Dnsmasq is configured to serve, including those without leases. The result reports its access level throughresult_access(). A forbidden (403) lease, Kea DHCPv4 settings or Dnsmasq range endpoint, including a cached denial, reports Status Access: that endpoint contributes nothing, so leases and interfaces it would have supplied may be missing. Otherwise the result reports Configuration Access. A missing (404) endpoint means its backend is not installed and contributes nothing. With the defaultthrow_errors=False, a Kea reservation endpoint that cannot be read only drops reservation detail, and the method returnsNone(unknown) when any lease endpoint fails with another error or returns a malformed payload, and when a configuration endpoint does so without a denial elsewhere establishing Status Access. Whenself._throw_errorsisTrue, a failed request raisesOPNsenseErrorinstead, specificallyOPNsensePrivilegeMissingfor a forbidden (403) endpoint; a 404 never raises, and a malformed payload still returnsNone.
- Mapping with
- Return type:
- class OPNsenseClient.ArpNdpEntry(mac, valid_mac, ipv4_address, ipv6_address, hostname, manufacturer, expired, interface, expires, arp_type, interface_name=None, interface_description=None, permanent=False)
Normalized neighbor row, with copied metadata isolated from its source.
- Parameters:
- expired
Expiration flag normalized by
coerce_bool. Nonzero numbers and trimmed case-insensitive1,true,yes, oronstrings are True; absent flags and other values are False.- Type:
- interface
Copied interface description, falling back to the interface identifier when the description is missing or blank.
- Type:
- class OPNsenseClient.ArpNdpTable(entries, unparsed_row_count, raw_rows, fetched_at=<factory>)
Normalized ARP or NDP table returned by one lookup.
- Parameters:
- entries
One entry for every mapping row, in source order. Rows with missing or invalid identities are retained. Strict MAC/IP fields are None when invalid; the permissively normalized
mactext is preserved.- Type:
tuple[ArpNdpEntry, …]
- unparsed_row_count
Number of source rows that are not mappings and therefore have no entry. A nonzero count means the entries may not describe the whole table.
- Type:
- raw_rows
Deep copies of every source row in source order, with mapping rows copied as plain dicts, isolated from both the response and the entries, for diagnostics and access to original or unknown fields.
- fetched_at
UTC-aware time when this table was normalized. The value stays fixed for the lifetime of this table.
- Type:
datetime
- class OPNsenseClient.HostObservation(mac, ip, last_seen)
One validated MAC and IP sighting from OPNsense host discovery.
- last_seen
UTC-aware timestamp when the host was observed.
- Type:
datetime
- class OPNsenseClient.HostObservations(source, entries)
Validated host-discovery observations and their data source.
- Parameters:
source (Literal['discovery', 'arp-ndp'])
entries (tuple[HostObservation, ...])
- source
Source of the observation result.
arp-ndpmeans host discovery is disabled and has no timestamps.- Type:
Literal[‘discovery’, ‘arp-ndp’]
- entries
Timestamped discovery entries; empty for the timestamp-free
arp-ndpfallback.- Type: