+def parse_net(netstr):
+ try: sl = netstr.index('/')
+ except ValueError: raise ValueError('missing mask')
+ addr = parse_address(netstr[:sl])
+ if netstr[sl + 1:].isdigit():
+ n = int(netstr[sl + 1:], 10)
+ mask = (1 << 32) - (1 << 32 - n)
+ else:
+ mask = parse_address(netstr[sl + 1:])
+ if addr&~mask: raise ValueError('network contains bits set beyond mask')
+ return addr, mask
+