python参数解析,argparse模块

本文介绍了一个高效Python脚本,用于自动破解Apache Tomcat登录凭证,旨在提高安全意识并展示如何通过编程手段识别和防范此类漏洞。脚本提供基本用法示例,包括目标主机和线程数的参数设定。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直接上代码吧

# coding=utf-8
import argparse 
import textwrap
import sys

__author__ = 'HATE_'

def getargs(): 
    # * A high-efficiency automatic program used for cracking Apache Tomcat\'s log-on credential, Powered by Tank  * 
    parser = argparse.ArgumentParser(prog='example.py', formatter_class=argparse.RawTextHelpFormatter, description=textwrap.dedent('''
    For Example:
    python example.py --host 127.0.0.1:8080 --threads 10'''))
    
    parser.add_argument('--host', metavar='host', type=str, help=' the host of target,including port') 
    parser.add_argument('--threads', metavar='threads', type=int, help=' The numbers of threads per process') 

    if(len(sys.argv[1:]) == 0): 
        sys.argv.append('-h') 
    return parser.parse_args() 

if __name__ == '__main__':
    paramsargs = getargs()
    print paramsargs.host
    print paramsargs.threads


输出

C:\Users\test\Desktop>python search
usage: example.py [-h] [--host host] [--threads threads]

For Example:
python example.py --host 127.0.0.1:8080 --threads 10

optional arguments:
  -h, --help         show this help message and exit
  --host host         the host of target,including port
  --threads threads   The numbers of threads per process



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值