-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharguments.py
55 lines (47 loc) · 2.25 KB
/
arguments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import argparse
from argparse import RawTextHelpFormatter
# Redefines argparse's default usage/help prefix
class HelpFormatter(argparse.HelpFormatter):
def add_usage(self, usage, actions, groups, prefix=None):
if prefix is None:
prefix = ''
return super(HelpFormatter, self).add_usage(
usage, actions, groups, prefix)
def parse_args():
''' Defines arguments '''
# Custom usage/help
main_args = """
Usage:
python getdc.py -d contoso.local
python getdc.py -d contoso-a.local constoso-b.local
python getdc.py -d contoso.local -n 8.8.8.8
python getdc.py -d contoso.local -n ns1.contoso.local
python getdc.py -d contoso.local -n ns1.contoso.local -f host
python getdc.py -d contoso.local -e
Required arguments:
[-d, --domain] define domain, accepted values 'hostname', 'hostnames(seperate by a space)'
Optional arguments:
[-n, --nameserver] define nameserver, accepted values 'hostname', 'ipaddress'
[-f, --format] format output type, accepted values 'json(default)', 'host', 'ip', 'hostip', 'zerologon'
[-e, --exchange] optionally retrieve exchange hosts
[-v, --verbose] toggle debug meesages to stdout
"""
# Define parser
parser = argparse.ArgumentParser(formatter_class=HelpFormatter, description='', usage=main_args, add_help=False)
# Main argument group
main_group = parser.add_argument_group('main_args')
main_group.add_argument('-d', '--domain', required=True, type=str, metavar='', default='', help='Domain required', nargs='+')
main_group.add_argument('-n', '--nameserver', required=False, type=str, metavar='', default='', help='Define Nameserver')
main_group.add_argument('-f', '--format', required=False, type=str, default='json', choices=['json', 'host', 'ip', 'hostip', 'zerologon'])
main_group.add_argument('-e', '--exchange', required=False, action='store_true')
# Mutually Exclusive group
mutually_exclusive_group = parser.add_mutually_exclusive_group()
mutually_exclusive_group.add_argument('-v', '--verbose', action='store_true')
# Initiate parser instance
args = parser.parse_args()
return args
def main():
import arguments
arguments.parse_args()
if __name__ == "__main__":
main()