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.

Parameters:

resolve_hostnames (bool) – Whether reverse DNS lookups should be requested.

Returns:

Unmodified rows, or None when unavailable or malformed.

Return type:

list | None

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 total does 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 total does 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.

Returns:

The historical {"source": ..., "rows": ...} shape.

Discovery rows contain normalized mac, ip, and UTC last_seen values. A disabled discovery service returns {"source": "arp-ndp", "rows": []}. An unavailable endpoint or malformed response returns None.

Return type:

dict[str, Any] | None

async OPNsenseClient.get_host_observation_entries()

Return validated host observations as immutable typed entries.

Returns:

Frozen normalized observations, including an empty

arp-ndp result 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_interfaces keyed by

interface name and leases keyed 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.

Return type:

dict[str, Any]

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:
  • mac (str | None)

  • valid_mac (str | None)

  • ipv4_address (str | None)

  • ipv6_address (str | None)

  • hostname (str | None)

  • manufacturer (str | None)

  • expired (bool)

  • interface (object)

  • expires (object)

  • arp_type (object)

  • interface_name (object)

  • interface_description (object)

  • permanent (bool)

mac

Permissively normalized MAC address, including malformed values.

Type:

str | None

valid_mac

Canonical six-octet MAC address, or None if invalid.

Type:

str | None

ipv4_address

Canonical IPv4 address, or None for other input.

Type:

str | None

ipv6_address

Canonical IPv6 address with any interface scope retained.

Type:

str | None

hostname

Trimmed hostname with surrounding question marks removed.

Type:

str | None

manufacturer

Trimmed manufacturer, or None if absent or blank.

Type:

str | None

expired

Expiration flag normalized by coerce_bool. Nonzero numbers and trimmed case-insensitive 1, true, yes, or on strings are True; absent flags and other values are False.

Type:

bool

interface

Copied interface description, falling back to the interface identifier when the description is missing or blank.

Type:

object

expires

Copied raw expiration metadata.

Type:

object

arp_type

Copied raw neighbor entry type.

Type:

object

interface_name

Copied interface identifier from intf or interface.

Type:

object

interface_description

Copied interface description from intf_description.

Type:

object

permanent

Permanent-entry flag normalized by coerce_bool.

Type:

bool

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 mac text 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:

int

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.

Type:

tuple[object, …]

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.

Parameters:
mac

Canonical lowercase six-octet MAC address.

Type:

str

ip

Compressed IPv4 or IPv6 address.

Type:

str

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

Source of the observation result. arp-ndp means host discovery is disabled and has no timestamps.

Type:

Literal[‘discovery’, ‘arp-ndp’]

entries

Timestamped discovery entries; empty for the timestamp-free arp-ndp fallback.

Type:

tuple[DHCPMixin.HostObservation, …]