cmdline.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Author: hywell
  5. @Email: hywell.28@gmail.com
  6. @Blog: iassas.com
  7. @Date: 2019/10/16 16:04
  8. """
  9. import argparse
  10. import os
  11. import sys
  12. from lib.core.data import logger
  13. def parse_args():
  14. """"
  15. This function parses the command line parameters and arguments.
  16. """
  17. parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description='''
  18. python AWIScan.py -i 10.10.10.10 -l 1
  19. python AWIScan.py -f target.com -l 1''', epilog="Believe that with the above description, " +
  20. "you can start working right away. Wish you success")
  21. group = parser.add_mutually_exclusive_group()
  22. group.add_argument("-i", "--ip", help="scan a target or network(e.g. target.com ,192.168.1.1[/24], "
  23. "192.168.1.1-192.168.1.100)")
  24. group.add_argument("-f", "--file", help="load target from targetFile (e.g. target.txt)")
  25. parser.add_argument("-l", "--level", type=int, choices=[1, 2, 3], default=1,
  26. help="This option is used to provide the scan level.")
  27. args = parser.parse_args()
  28. if args.ip:
  29. logger.info("[AWIScan] Load targets from: %s" % args.ip)
  30. base_targets = [args.ip]
  31. return base_targets, args.level
  32. elif args.file:
  33. if os.path.exists(args.file):
  34. logger.info("[AWIScan] Load targets from: %s" % args.file)
  35. base_targets = []
  36. with open(args.file, 'r', encoding='utf-8') as f:
  37. tars = f.readlines()
  38. for target in tars:
  39. target = target.strip('\n')
  40. base_targets.append(target)
  41. return base_targets, args.level
  42. else:
  43. logger.error("[AWIScan] {} file is not exist.".format(args.file))
  44. sys.exit(0)
  45. else:
  46. parser.print_help()
  47. sys.exit(0)