code: def parse_add_loopback():
      
  
      class Add(argparse.Action):
  
          def __call__(self, parser, args, values, option_string=None):
              try:
                  ipaddress.IPv4Interface("{}/{}".format(values[1], values[2]))
              except ipaddress.AddressValueError as e:
                  raise argparse.ArgumentTypeError("Invalid IP address: {}".format(e))
              except ipaddress.NetmaskValueError as e:
                  raise argparse.ArgumentTypeError("Invalid subnet mask: {}".format(e))
              setattr(args, self.dest, values)
      return Add
docs: Validate params when adding a loopback adapter