Get closest parent prefix from an IP Address #9086

Closed
opened 2025-12-29 20:45:16 +01:00 by adam · 4 comments
Owner

Originally created by @llamafilm on GitHub (Jan 13, 2024).

NetBox version

v3.6.9

Feature type

New functionality

Proposed functionality

Given an IP address, I'd like to get the closest prefix which contains that address. I see FR #1737 raised for exactly this, but the fix seems to miss the mark. The contains filter returns all containing prefixes, and the original request was to return only the closest one. For example, api/ipam/prefixes/?contains=10.37.152.65/32 returns both 10.37.0.0/16 and 10.37.152.64/26.

Use case

I'd like to create DHCP reservations in BloxOne DDI based on an IP Address / MAC combination from Netbox. The BloxOne API call requires the parent ID for this. So I've added Parent ID as a custom field to all prefixes in Netbox.

Database changes

No response

External dependencies

No response

Originally created by @llamafilm on GitHub (Jan 13, 2024). ### NetBox version v3.6.9 ### Feature type New functionality ### Proposed functionality Given an IP address, I'd like to get the _closest_ prefix which contains that address. I see FR #1737 raised for exactly this, but the fix seems to miss the mark. The `contains` filter returns _all_ containing prefixes, and the original request was to return only the closest one. For example, `api/ipam/prefixes/?contains=10.37.152.65/32` returns both 10.37.0.0/16 and 10.37.152.64/26. ### Use case I'd like to create DHCP reservations in BloxOne DDI based on an IP Address / MAC combination from Netbox. ~~The BloxOne [API call](https://csp.infoblox.com/apidoc?url=https%3A%2F%2Fcsp.infoblox.com%2Fapidoc%2Fdocs%2FIpamsvc#/fixed_address/fixed_addressCreate) requires the parent ID for this. So I've added Parent ID as a custom field to all prefixes in Netbox.~~ ### Database changes _No response_ ### External dependencies _No response_
adam added the type: feature label 2025-12-29 20:45:16 +01:00
adam closed this issue 2025-12-29 20:45:16 +01:00
Author
Owner

@llamafilm commented on GitHub (Jan 16, 2024):

I must have misread the documentation or it changed. Parent ID is actually not required by BloxOne. So I don't actually need this feature, although I still think it might be useful in some circumstances.

@llamafilm commented on GitHub (Jan 16, 2024): I must have misread the documentation or it changed. Parent ID is actually not required by BloxOne. So I don't actually need this feature, although I still think it might be useful in some circumstances.
Author
Owner

@jeffgdotorg commented on GitHub (Jan 16, 2024):

Closing since OP indicates the functionality described is not actually needed for their use case, and is achievable via minimal post-processing in case someone else out there turns out to need it.

@jeffgdotorg commented on GitHub (Jan 16, 2024): Closing since OP indicates the functionality described is not actually needed for their use case, and is achievable via minimal post-processing in case someone else out there turns out to need it.
Author
Owner

@jeremystretch commented on GitHub (Jan 17, 2024):

The contains filter returns all containing prefixes, and the original request was to return only the closest one.

You can just grab the last prefix in the list.

@jeremystretch commented on GitHub (Jan 17, 2024): > The contains filter returns all containing prefixes, and the original request was to return only the closest one. You can just grab the last prefix in the list.
Author
Owner

@llamafilm commented on GitHub (Jan 17, 2024):

Is the list always in order of least to most specificity? I assumed it was unordered.

@llamafilm commented on GitHub (Jan 17, 2024): Is the list always in order of least to most specificity? I assumed it was unordered.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9086