code: def valid_ipv4(ip):
      
      match =  _valid_ipv4.match(ip)
      if match is None:
          return False
  
      octets  = match.groups()
      if len(octets) != 4:
          return False
  
      first = int(octets[0])
      if first < 1 or first > 254:
          return False
  
      for i in range(1, 4):
          octet = int(octets[i])
          if octet < 0 or octet > 255:
              return False
  
      return True
docs: check if ip is a valid ipv4