mcjones.ca

Mask Change of a Prefix in Netbox in Python

import pynetbox

def main():
    nb = pynetbox.api('NETBOX_URL', 'NETBOX_TOKEN')

    ip_addresses = nb.ipam.ip_addresses.filter(parent="192.168.0.0/24")
    for ip in ip_addresses:
        if "/32" in str(ip):
            corrected = str(ip)[:-3] + "/24"
            ip.address = corrected
            ip.display = corrected
            ip.save()
            print ip + " -> " + corrected

if __name__ == '__main__':
    main()