+
+# Helper functions for converting to CIDR notation
+def get_net_size(netmask):
+ binary_str = ''
+ for octet in netmask:
+ binary_str += bin(int(octet))[2:].zfill(8)
+ return str(len(binary_str.rstrip('0')))
+
+def to_cidr(ipaddr, netmask):
+ # validate input
+ inet_aton(ipaddr)
+ inet_aton(netmask)
+
+ ipaddr = ipaddr.split('.')
+ netmask = netmask.split('.')
+
+ net_start = [str(int(ipaddr[x]) & int(netmask[x])) for x in range(0,4)]
+ return '.'.join(net_start) + '/' + get_net_size(netmask)
+
+def ipaddr_range(network, broadcast):
+ start = network.split('.')
+ end = broadcast.split('.')
+
+ # Assume interface always claims the first address in the block
+ start[3] = str(int(start[3]) + 2)
+ end[3] = str(int(end[3]) - 1)
+
+ return '.'.join(start) + ',' + '.'.join(end)
+