CLI entrypoint. This function is responsible for argument parsing, config layering (CLI > saved setup > built-in defaults), mode dispatch and result handling.
()
| 122 | |
| 123 | |
| 124 | def main() -> None: |
| 125 | """CLI entrypoint. |
| 126 | |
| 127 | This function is responsible for argument parsing, config layering |
| 128 | (CLI > saved setup > built-in defaults), mode dispatch and result handling. |
| 129 | """ |
| 130 | stdin_domain_sentinel = "__stdin_domain__" |
| 131 | parser = argparse.ArgumentParser( |
| 132 | prog="KNOCKPY", |
| 133 | description=( |
| 134 | f"knockpy v.{__version__} - Subdomain discovery and security checks\n" |
| 135 | "CLI options > saved setup (--setup) > built-in defaults.\n" |
| 136 | "https://github.com/guelfoweb/knockpy" |
| 137 | ), |
| 138 | ) |
| 139 | target_group = parser.add_argument_group("Target") |
| 140 | target_group.add_argument( |
| 141 | "-d", |
| 142 | "--domain", |
| 143 | nargs="?", |
| 144 | const=stdin_domain_sentinel, |
| 145 | help="Domain to analyze. If used without value, reads from stdin.", |
| 146 | ) |
| 147 | target_group.add_argument("-f", "--file", help="File with domains, one per line.") |
| 148 | |
| 149 | mode_group = parser.add_argument_group("Scan Modes") |
| 150 | mode_group.add_argument("--recon", help="Enable reconnaissance.", action="store_true") |
| 151 | mode_group.add_argument("--bruteforce", "--brute", help="Enable bruteforce.", action="store_true") |
| 152 | mode_group.add_argument("--wildcard", help="Test wildcard and exit.", action="store_true") |
| 153 | mode_group.add_argument( |
| 154 | "--exclude", |
| 155 | nargs=2, |
| 156 | action="append", |
| 157 | metavar=("TYPE", "VALUE"), |
| 158 | help="Exclude matches. TYPE=status, length/lenght (e.g. 275), or body. Repeatable.", |
| 159 | ) |
| 160 | mode_group.add_argument( |
| 161 | "--verbose", |
| 162 | help="Verbose checks for single-domain scan only (without --recon/--bruteforce).", |
| 163 | action="store_true", |
| 164 | ) |
| 165 | mode_group.add_argument( |
| 166 | "--test", |
| 167 | help="With --recon, test each recon service and show which fails or returns data.", |
| 168 | action="store_true", |
| 169 | ) |
| 170 | |
| 171 | setup_group = parser.add_argument_group("Setup and Reports") |
| 172 | setup_group.add_argument( |
| 173 | "--setup", |
| 174 | help="Interactive setup: save runtime defaults and API keys in the local DB.", |
| 175 | action="store_true", |
| 176 | ) |
| 177 | setup_group.add_argument( |
| 178 | "--report", |
| 179 | nargs="?", |
| 180 | const="choose", |
| 181 | help="Report mode. In interactive terminals it opens the menu (show/delete/export/search/findings).", |
no test coverage detected