-
Notifications
You must be signed in to change notification settings - Fork 2
/
NumNinja (CUI) - Multiprocessing.py
152 lines (115 loc) · 6.53 KB
/
NumNinja (CUI) - Multiprocessing.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import multiprocessing
import time; import os
from tqdm import tqdm
from termcolor import colored
import colorama
colorama.init()
correctInput = False
BANNER1 = colored('''
███▄ █ █ ██ ███▄ ▄███▓ ███▄ █ ██▓ ███▄ █ ▄▄▄██▀▀▀▄▄▄
██ ▀█ █ ██ ▓██▒▓██▒▀█▀ ██▒ ██ ▀█ █ ▓██▒ ██ ▀█ █ ▒██ ▒████▄
▓██ ▀█ ██▒▓██ ▒██░▓██ ▓██░▓██ ▀█ ██▒▒██▒▓██ ▀█ ██▒ ░██ ▒██ ▀█▄
▓██▒ ▐▌██▒▓▓█ ░██░▒██ ▒██ ▓██▒ ▐▌██▒░██░▓██▒ ▐▌██▒▓██▄██▓ ░██▄▄▄▄██
▒██░ ▓██░▒▒█████▓ ▒██▒ ░██▒▒██░ ▓██░░██░▒██░ ▓██░ ▓███▒ ▓█ ▓██▒
░ ▒░ ▒ ▒ ░▒▓▒ ▒ ▒ ░ ▒░ ░ ░░ ▒░ ▒ ▒ ░▓ ░ ▒░ ▒ ▒ ▒▓▒▒░ ▒▒ ▓▒█░
░ ░░ ░ ▒░░░▒░ ░ ░ ░ ░ ░░ ░░ ░ ▒░ ▒ ░░ ░░ ░ ▒░ ▒ ░▒░ ▒ ▒▒ ░
░ ░ ░ ░░░ ░ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ▒
░ ░ ░ ░ ░ ░ ░ ░ ░ ░''', 'blue')
BANNER2 = colored(''' ----------------------------------------------''', 'blue')
BANNER3 = colored(''' || NumNinja: The Numeric Wordlist Generator ||''', 'red')
BANNER4 = colored(''' ----------------------------------------------''', 'blue')
def printBanner():
print(BANNER1), print(BANNER2), print(BANNER3), print(BANNER4)
########## Method Elements ###########
def zeros1(numList, chunkOne, Output, digitStr):
try:
with open(Output, 'a') as file:
for number in numList[0:chunkOne]:
file.write((digitStr + "\n") % number)
except KeyboardInterrupt:
raise KeyboardInterrupt
def zeros2(numList, chunkOne, chunkTwo, Output, digitStr):
try:
with open(Output, 'a') as file:
for number in numList[chunkOne:chunkTwo]:
file.write((digitStr + "\n") % number)
except KeyboardInterrupt:
raise KeyboardInterrupt
def zeros3(numList, chunkTwo, chunkThree, Output, digitStr):
try:
with open(Output, 'a') as file:
for number in numList[chunkTwo:chunkThree]:
file.write((digitStr + "\n") % number)
except KeyboardInterrupt:
raise KeyboardInterrupt
def zeros4(numList, chunkThree, Output, digitStr):
try:
with open(Output, 'a') as file:
for number in numList[chunkThree:]:
file.write((digitStr + "\n") % number)
except KeyboardInterrupt:
raise KeyboardInterrupt
############### Main ###############
if __name__ == "__main__":
printBanner()
while (correctInput is False):
try:
minunit = int(input("\nEnter the minimum value (Default = zero): ") or 0)
maxunit = int(input("Enter the maximum value: "))
if maxunit > minunit:
Output = str(input("Enter output folder (Default = working folder):") or "./")
Output += "/"
print("\nMethods:-")
print("1. Leading Zeros\n2. Staightforward (currently under construction)")
method = int(input("\nSelect method number: ") or 1)
print("")
if (method == 1):
digits = int(input("Enter the number of digits: "))
digitStr = (f"%0{digits}d")
print("\nShow progress?")
print("1. Yes (slower)\n2. No (faster)")
progressPrompt = int(input("\nSelect option number (Default = No): ") or 2)
genunit = maxunit - minunit
numList = []
for i in range(minunit, maxunit + 1):
numList.append(i)
length = len(numList)
chunkOne = length // 4
chunkTwo = chunkOne * 2
chunkThree = chunkOne * 3
Output += ((digitStr) % minunit) + " to " + ((digitStr) % maxunit) + ".txt"
print(f"\nNumber of lines that will be generated: {genunit}")
print("\nWorking...", end='')
process1 = multiprocessing.Process(target=zeros1, args=[numList, chunkOne, Output, digitStr])
process2 = multiprocessing.Process(target=zeros2, args=[numList, chunkOne, chunkTwo, Output, digitStr])
process3 = multiprocessing.Process(target=zeros3, args=[numList, chunkTwo, chunkThree, Output, digitStr])
process4 = multiprocessing.Process(target=zeros4, args=[numList, chunkThree, Output, digitStr])
start = time.time()
processPool = [process1, process2, process3, process4]
for process in processPool:
process.start()
for process in processPool:
process.join()
completionTime = time.time() - start
rate = genunit // completionTime
print(f"\n\nThe task completed successfully in {completionTime} seconds. (at ~{rate} lines/sec)")
print("Press Enter to exit.")
input()
break
elif (minunit == maxunit):
print("\nThe minimum value cannot be equal to the maximum value. Please try again.\n")
elif (minunit > maxunit):
print("\nThe minimum value cannot be greater than the maximum value. Please try again.\n")
except ZeroDivisionError:
print("\n\nThe task completed successfully in zero seconds.")
print("Press Enter to exit.")
input()
break
except KeyboardInterrupt:
print("\nCTRL ^C\n\nThrew a wrench in the works.")
print("Press Enter to exit.")
input()
os._exit()
except:
print("\nOne of more of the inputs are invalid. This can happen when any spaces or other characters have been entered instead of numbers. Please try again.\n")
continue