aboutsummaryrefslogtreecommitdiff
blob: f633cd5b0f38286d066dc5afbe6b80d56ac5c677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import re

def validate(userIn):
    ipVer4 = "^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$"
    ipVer6Std = "^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$"
    ipVer6Hex = "^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$"

    if(re.match(ipVer4, userIn)!=None):
        return True
    elif(re.match(ipVer6Std, userIn)!=None):
        return True
    elif(re.match(ipVer6Hex, userIn)!=None):
        return True

    return False