Projects STRLCPY RTSPbrute Commits bd5980f7
🤬
  • Add check for valid port during argument parsing

  • Loading...
  • Woolf committed 4 years ago
    bd5980f7
    1 parent 4f76f80e
  • ■ ■ ■ ■ ■ ■
    rtspbrute/modules/cli/input.py
    1 1  import argparse
    2 2  from pathlib import Path
     3 +from typing import Any
    3 4   
    4 5  from rtspbrute import DEFAULT_CREDENTIALS, DEFAULT_ROUTES, DEFAULT_TARGETS
    5 6   
    skipped 10 lines
    16 17   return ", ".join(action.option_strings) + " " + args_string
    17 18   
    18 19   
    19  -def file_path(path):
    20  - if Path(path).exists():
    21  - return Path(path)
     20 +def file_path(value: Any):
     21 + if Path(value).exists():
     22 + return Path(value)
    22 23   else:
    23  - raise argparse.ArgumentTypeError(f"{path} is not a valid path")
     24 + raise argparse.ArgumentTypeError(f"{value} is not a valid path")
     25 + 
     26 + 
     27 +def port(value: Any):
     28 + if int(value) in range(65536):
     29 + return int(value)
     30 + else:
     31 + raise argparse.ArgumentTypeError(f"{value} is not a valid port")
    24 32   
    25 33   
    26 34  fmt = lambda prog: CustomHelpFormatter(prog)
    skipped 14 lines
    41 49   "--ports",
    42 50   nargs="+",
    43 51   default=[554],
    44  - type=int,
     52 + type=port,
    45 53   help="the ports on which to search for RTSP streams",
    46 54  )
    47 55  parser.add_argument(
    skipped 42 lines
Please wait...
Page is in error, reload to recover