def str_to_ipmask(ipmask):
v = ipmask.split("<STR_LIT:/>")<EOL>if len(v) > <NUM_LIT:2>: raise Exception("<STR_LIT>")<EOL>mask_ip = ip2hex(v[<NUM_LIT:0>])<EOL>if mask_ip is None: raise Exception("<STR_LIT>")<EOL>mask = v[<NUM_LIT:1>] if len(v) == <NUM_LIT:2> else <NUM_LIT:32><EOL>try:<EOL><INDENT>mask = (<NUM_LIT> >> int(mask)) & <NUM_LIT><EOL><DEDENT>except:<EOL><INDENT>mask = ip2hex(v[<NUM_LIT:1>])<EOL><DEDENT>if mask is None: raise Exception("<STR_LIT>")<EOL>return mask_ip, mask<EOL>
Converts a string with the notation ip/mask (e.g. 192.168.1.1/24 or 192.168.1.1/255.255.255.0) to an hex mask