For the comment made by CaTalyst.X, note that you need to switch to the code for it to work.
It:
cidrs = netaddr.ip_range_to_cidrs('54.64.0.0', '54.71.255.255')
You need to become the following:
cidrs = netaddr.iprange_to_cidrs('54.64.0.0', '54.71.255.255')
If you use the first code instance, you will get an exception, since ip_range_to_cidrs is not a valid attribute of the netaddr method.
source share