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
评论列表
文章目录