Skip to content

Commit

Permalink
Added color by status code #29
Browse files Browse the repository at this point in the history
used console cargo v0.15.0 for coloring the output in terminal
  • Loading branch information
ChandanChainani committed Oct 27, 2021
1 parent d3735cb commit 5cfc2bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ regex = "^1.1.7"
galvanic-test = "^0.2.0"
galvanic-assert = "0.8.7"
criterion = "^0.2.11"
console = "^0.15.0"

[[bench]]
name = "rustbuster"
Expand Down
24 changes: 22 additions & 2 deletions src/dirbuster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::sync::mpsc::channel;
use std::sync::mpsc::Sender;
use std::{time::SystemTime};
use indicatif::{ProgressBar, ProgressStyle};
use console::style;

pub mod result_processor;
pub mod utils;
Expand All @@ -36,6 +37,25 @@ pub struct DirBuster {
pub output: String,
}

fn color_by_status_code(code: &str) -> String {
if code.starts_with("1") {
return style(code).blue().to_string();
}
else if code.starts_with("2") {
return style(code).green().to_string();
}
else if code.starts_with("3") {
return style(code).color256(226).to_string();
}
else if code.starts_with("4") {
return style(code).color256(208).to_string();
}
else if code.starts_with("5") {
return style(code).red().to_string();
}
return style(code).bold().to_string();
}

impl DirBuster {
pub fn run(self) {
let mut current_numbers_of_request = 0;
Expand Down Expand Up @@ -150,7 +170,7 @@ impl DirBuster {
bar.println(format!(
"{}\t{}{}{}{}",
msg.method,
msg.status,
color_by_status_code(&msg.status),
"\t".repeat(n_tabs),
msg.url,
extra
Expand All @@ -166,7 +186,7 @@ impl DirBuster {
save_dir_results(&output, &result_processor.results);
}
}

fn make_request_future(
&self,
tx: Sender<SingleDirScanResult>,
Expand Down

0 comments on commit 5cfc2bf

Please sign in to comment.