1 def is_ipv4(ip): 2 p = re.compile('^((25[0-5]|2[0-4]d|[01]?dd?).){3}(25[0-5]|2[0-4]d|[01]?dd?)$') 3 return p.match(ip)