Write a python function to find and print if IP address given is a valid IP address or not


Topic: Write a python function to find and print if IP address given is a valid IP address or not

Solution

import re
 
def Validate_IP(IP):
    regex = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|"\
            "2[0-4][0-9]|25[0-5])\\.){3}"\
            "([0-9]|[1-9][0-9]|1[0-9][0-9]|"\
            "2[0-4][0-9]|25[0-5])"
     
    regex1 = "((([0-9a-fA-F]){1,4})\\:){7}"\
             "([0-9a-fA-F]){1,4}"
     
    p = re.compile(regex)
    p1 = re.compile(regex1)
 
    if (re.search(p, IP)):
        return "Valid IPv4"
 
    elif (re.search(p1, IP)):
        return "Valid IPv6"
 
    return "Invalid IP"
	



List all Python Programs