arnold.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:nav 作者: UNINETT 项目源码 文件源码
def find_input_type(ip_or_mac):
    """Try to determine whether input is a valid ip-address,
    mac-address or an swportid. Return type and reformatted input as a
    tuple"""
    # Support mac-adresses on xx:xx... format
    ip_or_mac = str(ip_or_mac)
    mac = ip_or_mac.replace(':', '')

    input_type = "UNKNOWN"
    if is_valid_ip(ip_or_mac, use_socket_lib=True):
        input_type = "IP"
    elif re.match("^[A-Fa-f0-9]{12}$", mac):
        input_type = "MAC"
    elif re.match(r"^\d+$", ip_or_mac):
        input_type = "SWPORTID"

    return input_type
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号