get all IPs assigned under a prefix with an API call

1,359 views
Skip to first unread message

harshad sowani

unread,
Dec 1, 2021, 4:01:54 PM12/1/21
to NetBox
Hi,
I'm trying to get (via the API) a list of all IP addresses that have been 
1. defined in netbox and 
2. fall under prefixes that have a certain role assigned.

The UI returns a list of all IP address under a particular prefix if i browse to /ipam/prefixes/<prefixid>/ip-addresses/  - is there a way to do this via the API?

Thanks!


Brian Candler

unread,
Dec 1, 2021, 4:16:43 PM12/1/21
to NetBox
On Wednesday, 1 December 2021 at 21:01:54 UTC harsha...@gmail.com wrote:
The UI returns a list of all IP address under a particular prefix if i browse to /ipam/prefixes/<prefixid>/ip-addresses/  - is there a way to do this via the API?

class IPAddressFilterSet(PrimaryModelFilterSet, TenancyFilterSet):
...
    parent = django_filters.CharFilter(
        method='search_by_parent',
        label='Parent prefix',
    )

That is, querying /api/ipam/ip-addresses/?parent=1.2.3.0%2F24 should do it

harshad sowani

unread,
Dec 1, 2021, 4:18:38 PM12/1/21
to NetBox
Exactly what I needed - thanks for the super quick response!
Reply all
Reply to author
Forward
0 new messages