Skip to content

Commit 0291a07

Browse files
committed
--no-colors option
1 parent fbe4d32 commit 0291a07

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ optional arguments:
7070
--capitalize Transform 'word' into 'Word'.
7171
--strip-extension Strip word extension: word.ext into word
7272
--alpha Filter non alphanumeric words from wordlist
73+
--no-progress Don't show tested words and progress. (For dumb terminals)
74+
--no-colors Don't use output colors to keep output clean, e.g. when redirecting output to file
7375

7476
License, requests, etc: https://github.com/deibit/cansina
7577
```
@@ -84,7 +86,7 @@ Screenshot
8486
Installing dependencies
8587
=======================
8688

87-
pip install --user requests[security] or pip install -r requeriments.txt
89+
pip install --user requests[security] or pip install -r requirements.txt
8890

8991
(try removing --user and install with sudo in case of errors)
9092

cansina.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ def _make_cookie_jar(_cookies):
186186
help="Filter non alphanumeric words from wordlist", default=False, action="store_true")
187187
parser.add_argument('--no-progress', dest='no_progress',
188188
help="Don't show tested words and progress. (For dumb terminals)", default=False, action="store_true")
189+
parser.add_argument('--no-colors', dest='no_colors',
190+
help="Disable coloring. (For dumb terminals)", default=False, action="store_true")
189191

190192
args = parser.parse_args()
191193

@@ -401,6 +403,7 @@ def _make_cookie_jar(_cookies):
401403
Console.show_content_type = show_content_type
402404
Console.header()
403405
Console.set_show_progress(False if args.no_progress else True)
406+
Console.set_show_colors(False if args.no_colors else True)
404407

405408
#
406409
# Create the thread_pool and start the daemonized threads

core/printer.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@ class Console:
8888
number_of_requests = 0
8989
number_of_threads = 0
9090
show_progress = True
91+
show_colors = True
9192

9293
@staticmethod
9394
def set_show_progress(show_progress):
9495
Console.show_progress = show_progress
9596

97+
def set_show_colors(show_colors):
98+
Console.show_colors = show_colors
99+
96100
@staticmethod
97101
def start_eta_queue(size):
98102
Console.eta_queue = ETAQueue(size, Console.number_of_requests, Console.number_of_threads)
@@ -122,22 +126,26 @@ def body(task):
122126
elif os.name == 'nt':
123127
return
124128

129+
to_format = "{1: ^3} | {2: >10} | {3: >6} | {4: >4} | {7} [{0: >2}%] - {5: ^9} - {6}"
130+
to_format_without_progress = "{0: ^3} | {1: >10} | {2: >6} | {3: >4} | {5:^} {4}"
131+
125132
color = ""
126-
if task.response_code == "200":
127-
color = GREEN
128-
if task.response_code == "401" or task.response_code == "403":
129-
color = RED
130-
if task.response_code == "404" and (not task.response_code in task.banned_response_codes):
131-
color = GRAY
132-
if task.response_code == "301" or task.response_code == "302":
133-
color = LBLUE
134-
if task.response_code.startswith('5') or task.response_code == '400':
135-
color = YELLOW
136-
if task.content_detected:
137-
color = MAGENTA
138-
139-
to_format = color + "{1: ^3} | {2: >10} | {3: >6} | {4: >4} | {7} [{0: >2}%] - {5: ^9} - {6}" + ENDC
140-
to_format_without_progress = color + "{0: ^3} | {1: >10} | {2: >6} | {3: >4} | {5:^} {4}" + ENDC
133+
if Console.show_colors:
134+
if task.response_code == "200":
135+
color = GREEN
136+
if task.response_code == "401" or task.response_code == "403":
137+
color = RED
138+
if task.response_code == "404" and (not task.response_code in task.banned_response_codes):
139+
color = GRAY
140+
if task.response_code == "301" or task.response_code == "302":
141+
color = LBLUE
142+
if task.response_code.startswith('5') or task.response_code == '400':
143+
color = YELLOW
144+
if task.content_detected:
145+
color = MAGENTA
146+
147+
to_format = color + to_format + ENDC
148+
to_format_without_progress = color + to_format_without_progress + ENDC
141149

142150
# User wants to see full path
143151
if Console.show_full_path:
@@ -176,7 +184,7 @@ def body(task):
176184
t_encode = t_encode[:abs(COLUMNS - Console.MIN_COLUMN_SIZE)]
177185

178186
# if an entry is about to be log, remove percentage and eta time
179-
if color and not task.response_code in task.banned_response_codes:
187+
if color is not None and not task.response_code in task.banned_response_codes:
180188
to_console = to_format_without_progress.format(task.response_code,
181189
task.response_size,
182190
task.number,
@@ -193,9 +201,9 @@ def body(task):
193201
t_encode, content_type)
194202

195203
sys.stdout.write(to_console[:COLUMNS-2])
204+
sys.stdout.write('\r')
196205

197206
sys.stdout.flush()
198-
sys.stdout.write('\r')
199207

200-
if not os.name == 'nt':
208+
if not os.name == 'nt' and Console.show_progress:
201209
sys.stdout.write("\x1b[0K")

0 commit comments

Comments
 (0)