0

Tools like dnsgen works with this both type of options:
Without any argument:
cat domains.txt | dnsgen - | someotherprogram
With argument:
dnsgen -w wordlist filename.txt

Can I make my program use - without argument i.e. dnsgen - style. Lets say my code is this and it can receive data from both stdin and wordlist

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-w', '--wordlist', help="Wordlist")
argv = parser.parse_args()
my_awesome_function(argv.wordlist)

So, my code reads only from wordlist. How can I make this both by wordlist and by stdin using - argument style?

1 Answer 1

1

May be not an elegant solution but, You can assign a dummy variable and make it store_true as below.

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-', "--_", action='store_true')
parser.add_argument('-w', '--wordlist', help="Wordlist")
argv = parser.parse_args()
my_awesome_function(argv.wordlist)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.