def parse_args(self, args: Optional[Sequence[str]] = None):
"""
Parse command line arguments and store checked and converted values in self.
`"By default, the argument strings are taken from sys.argv"
<https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.parse_args>`_
:type args: Optional[Sequence[str]]
:param args: argument strings
"""
# NOTE: Call to parse_args with namespace=self does not set logging_level with default value, if argument is not
# in provided args, for some reason.
parsed_args = self.parser.parse_args(args=args)
if CommandRequirement('airmon-ng').check():
# if airmon-ng is available, check for wireless interface name can be performed here,
# if airmon-ng is NOT available, wifimitmcli will terminate upon requirements check after parsing args.
# Check if provided interface name is recognized as wireless interface name.
for i in list_wifi_interfaces():
if i.name == parsed_args.interface.name:
break
else:
self.parser.error('argument interface: {} is not recognized as a valid wireless interface'.format(
parsed_args.interface.name)
)
# name to value conversion as noted in `self.init_parser`
self.logging_level = self.LOGGING_LEVELS_DICT[parsed_args.logging_level]
self.phishing_enabled = parsed_args.phishing
if parsed_args.capture_file:
# `"FileType objects understand the pseudo-argument '-' and automatically convert this into sys.stdin
# for readable FileType objects and sys.stdout for writable FileType objects:"
# <https://docs.python.org/3/library/argparse.html>`_
if parsed_args.capture_file is sys.stdout:
self.parser.error('argument -cf/--capture-file: stdout is not allowed')
# The capture_file is opened by `argparse.ArgumentParser.parse_args` to make sure its writable for us.
self.capture_file = parsed_args.capture_file
self.essid = parsed_args.essid
self.interface = parsed_args.interface
评论列表
文章目录