How do I validate the format of a MAC address?

前端 未结 11 1488
逝去的感伤
逝去的感伤 2020-12-15 05:59

What\'s the best way to validate that an MAC address entered by the user?

The format is HH:HH:HH:HH:HH:HH, where each H is a hexadecimal ch

11条回答
  •  青春惊慌失措
    2020-12-15 06:55

    #Just works Perfect
    #validate the MAC addr
    
    #!/usr/bin/python
    import re
    
    mac = "01-3e-4f-ee-23-af"
    
    result = re.match(r"([0-9a-fA-F]{2}[-:]){5}[0-9a-fA-F]{2}$",mac)
    
    if result:
        print ("Correct MAC")
    else:
        print ("Incorrect MAC")
    

提交回复
热议问题