python渗透测试之argparse的使用

一、前言

  最近研究了python渗透测试,在做渗透测试时不可少的一个模块就是argparse(python3)/optparse(python2);发现大家所提供的一些关于渗透测试的代码以及资料里面大多都用是optparse(python2),但是optparse在python2.7以后就被放弃且不再维护更新了,所以对于python3的用户来说还是需要用argparse,所以自己按照optparse的写法写了一下在渗透测试中argparse的用法。

二、argparse模块与optparse模块对比

1、optparse

import optparse

def main():
    parser = optparse.OptionParser('usage%prog '+'-H<target host> -u <user> -f <password list>')
    parser.add_option('-H', dest='tgtHost', type='string', help='specify target host')
    parser.add_option('-f', dest='passwdFile', type='string', help='specify password file')
    parser.add_option('-u', dest='user', type='string', help='specify the user')
    (options, args) = parser.parse_args()
    host = options.tgtHost
    passwdFile = options.passwdFile
    user = options.user

2、argparse

import argparse

def main():
    parser = argparse.ArgumentParser(description='pxssh暴力破解密码')
    parser.add_argument('-H',dest='tgtHost',type=str,help='specify target host')
    parser.add_argument('-f',dest='passwdFile',type=str,nargs='*',help='specify password file')
    parser.add_argument('-u',dest='user',type=str,help='specify the user')
    args = parser.parse_args()
    tgtHost = args.tgtHost
    passwdFile = args.passwdFile
    user = args.user

 

posted @ 2022-09-08 14:24  梅梅不想踩坑  阅读(83)  评论(0编辑  收藏  举报