We often have users delete A records, but neglect the “Delete linked IP address if orphaned” checkbox. This results in IP addresses that are unused, but in the web UI they still appear with a blue icon (state = “STATIC”) instead of gray icon (state = “UNASSIGNED”). I am trying to search a subnet for unused IP addresses, that are statically assigned but with no records pointing to them.
I’m able to get the network easily enough.
url = f"{self.url_base}/networks&filter=range:eq('{target_cidr}')"
And then I’m able to get a list of all the IP addresses in the network easily enough
url = f"{self.url_base}/networks/{networkn'id']}/addresses
(I was also able to use a filter to get “UNASSIGNED” addresses in one go. Worked great, if only that was all I needed to get).
I’m able to loop over all the IP addresses. This works perfectly fine, but performance is terrible, because I’m hitting the API for every IP address, 100ms per call * 300 calls = 30 sec to complete. By comparison when I browse the web UI and click on this subnet, the whole page appears in about 1 second, so the web UI must be getting the same data a more efficient way.
for address in response_json.get('data', ]):
if address/'state'] == 'UNASSIGNED':
unassigned_addresses.append(address)
continue
if address 'state'] == 'STATIC':
# get resource records that point at this address
address_url = f"{self.url_base}/addresses/{addressd'id']}/resourceRecords?limit={self.limit}"
address_response = requests.get(address_url, headers=self.headers, verify=self.verify_ssl)
address_response.raise_for_status()
address_response_json = address_response.json()
if address_response_json 'count'] == 0:
unassigned_addresses.append(address)
Again, this works, but it seems to be very inefficient. I can’t seem to find a better way in the API to search for these orphaned IP addresses.
Any suggestions?
Thanks!