Replies: 1 comment
-
Given that an "IP address" in Netbox also records the prefix length, you could just calculate it by masking with the prefix length. e.g. if the address is "10.11.12.13/24" then the prefix (if it exists) should be "10.11.12.0/24". Unfortunately, the prefix length which users enter manually is often wrong anyway :-( You can instead locate ancestor prefixes by querying for all prefixes which contain the given IP address. This is how the web UI does it in the IP address view: In nbshell:
If you sort this list by prefix length, and take the longest, then you have the nearest enclosing prefix object. Similar logic is used in the script here:
I don't think it does, but again you can search as per here to find ranges containing the given IP:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm on NetBox 3.1.8, but haven't noticed anything in the changelog that would mention something like this.
I noticed I can call the IPs of a Prefix via NBshell e.g.
Prefix.objects.get(id=1337).get_child_ips()
->RestrictedQuerySet [<IPAddress: 10.11.12.13/24>]
However i noticed the reverse is not possible, there is no method to
get_parent_prefix
or similar, however on the website there is a nice generated table, so the information has to be obtainable somehow. kind of the same goes for IP-Ranges, i guess it borrows all the methods from the prefixes.How do i accomplish this?
Kind Regards
Beta Was this translation helpful? Give feedback.
All reactions