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

def str_to_ipmask(ipmask):
    '''
    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
    '''
    v = ipmask.split("/")
    if len(v) > 2: raise Exception("bad mask format")
    mask_ip = ip2hex(v[0])
    if mask_ip is None: raise Exception("bad mask format")
    mask = v[1] if len(v) == 2 else 32
    try:
        mask = (0xffffffff00000000 >> int(mask)) & 0xffffffff
    except:
        mask = ip2hex(v[1])
    
    if mask is None: raise Exception("bad mask format")
    return mask_ip, mask