-
Notifications
You must be signed in to change notification settings - Fork 34
/
wgen.py
59 lines (49 loc) · 1.91 KB
/
wgen.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
56
57
58
59
import os
import sys
import time
import string
import argparse
import itertools
def createWordList(chrs, min_length, max_length, output):
"""
:param `chrs` is characters to iterate.
:param `min_length` is minimum length of characters.
:param `max_length` is maximum length of characters.
:param `output` is output of wordlist file.
"""
if min_length > max_length:
print ("[!] Please `min_length` must smaller or same as with `max_length`")
sys.exit()
if os.path.exists(os.path.dirname(output)) == False:
os.makedirs(os.path.dirname(output))
print ('[+] Creating wordlist at `%s`...' % output)
print ('[i] Starting time: %s' % time.strftime('%H:%M:%S'))
output = open(output, 'w')
for n in range(min_length, max_length + 1):
for xs in itertools.product(chrs, repeat=n):
chars = ''.join(xs)
output.write("%s\n" % chars)
sys.stdout.write('\r[+] saving character `%s`' % chars)
sys.stdout.flush()
output.close()
print ('\n[i] End time: %s' % time.strftime('%H:%M:%S'))
if __name__ == '__main__':
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
description='Python Wordlist Generator')
parser.add_argument(
'-chr', '--chars',
default=None, help='characters to iterate')
parser.add_argument(
'-min', '--min_length', type=int,
default=1, help='minimum length of characters')
parser.add_argument(
'-max', '--max_length', type=int,
default=2, help='maximum length of characters')
parser.add_argument(
'-out', '--output',
default='output/wordlist.txt', help='output of wordlist file.')
args = parser.parse_args()
if args.chars is None:
args.chars = string.printable.replace(' \t\n\r\x0b\x0c', '')
createWordList(args.chars, args.min_length, args.max_length, args.output)