Skip to content

Filter IP addresses by parent prefix in custom scripts #9487

Answered by candlerb
JulijusBertasius asked this question in Q&A

You must be logged in to vote

There's a method the other way round, on Prefix:

addrs = parent_prefix.get_child_ips()

If you still want to start with IPAddress.objects and filter downwards, then I suggest you copy the logic from the REST API IPAddressFilterSet here and here. The key part is:

            query = str(netaddr.IPNetwork(value.strip()).cidr)
            return queryset.filter(address__net_host_contained=query)

(you may want to filter on the value of VRF as well)

Replies: 1 comment 2 replies

You must be logged in to vote
2 replies
@Domoninic

@JulijusBertasius

Answer selected by JulijusBertasius
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants