- if isinstance(netmask, int):
- return net.netmask
- elif isinstance(netmask, basestring):
- return net.prefixlen
+ if isinstance(network, int) and (0 < network < 33):
+ return str(net.netmask)
+ elif isinstance(network, basestring):
+ return int(net.prefixlen)
+ else:
+ raise Exception("Value {0} is not a valid ipv4 netmask or network"
+ " prefix length".format(network))