DHCP, ARP, and NDP

Timestamped host observations

To use get_host_observations(), 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)

Return active ARP table entries.

Parameters:

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

Returns:

ARP rows from OPNsense, optionally with resolved hostnames,

including fields such as IP address, MAC address, interface, expiration, and entry type when provided by the endpoint. An unavailable endpoint, or an absent or malformed rows field, returns None rather than an authoritative empty table.

Return type:

list | None

async OPNsenseClient.get_ndp_table()

Return IPv6 neighbors from the OPNsense NDP table.

Returns:

Unmodified neighbor rows containing ip, mac,

intf, intf_description, and manufacturer when supplied. IPv6 addresses may include an interface scope suffix. Multiple addresses for the same MAC are preserved, including SLAAC and privacy addresses; DHCPv6 is not required. An empty list means a successful lookup found no neighbors. An unavailable endpoint or absent or malformed rows field returns None.

Return type:

list | None

async OPNsenseClient.get_host_observations()

Return timestamped MAC observations without changing neighbor inventories.

Returns:

Source and normalized rows containing mac, ip,

and UTC last_seen datetimes. discovery identifies packet observations; arp-ndp identifies the timestamp-free fallback when hostwatch is disabled. An unavailable endpoint, incomplete response, empty source, or malformed discovery row returns None rather than an authoritative empty inventory.

Return type:

dict[str, Any] | 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.

Return type:

dict[str, Any]