Skip to content

Commit

Permalink
Add raw output support.
Browse files Browse the repository at this point in the history
Signed-off-by: Edu4rdSHL <edu4rdshl@protonmail.com>
  • Loading branch information
Edu4rdSHL committed May 10, 2021
1 parent e2525b3 commit f20f6d6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ pub fn get_args() -> Args {
custom_resolvers: matches.is_present("custom-resolvers"),
custom_ports_range: matches.is_present("initial-port") || matches.is_present("last-port"),
fast_scan: matches.is_present("fast-scan"),
keep_nmap_logs: matches.is_present("keep-nmap-logs"),
no_keep_nmap_logs: matches.is_present("no-keep-nmap-logs"),
raw_output: matches.is_present("raw-output"),
files: return_matches_vec(&matches, "files"),
min_rate: value_t!(matches, "min-rate", String).unwrap_or_else(|_| String::new()),
resolvers: if matches.is_present("custom-resolvers") {
Expand Down
11 changes: 9 additions & 2 deletions src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ args:
takes_value: true
multiple: false

- keep-nmap-logs:
- no-keep-nmap-logs:
help: Keep Nmap XML files created in the logs/ folder for every scanned IP. This data will be useful for other tasks.
short: k
long: keep-nmap-logs
long: no-keep-nmap-logs
takes_value: false
multiple: false

- raw-output:
help: Use raw output instead of a table.
short: r
long: raw-output
takes_value: false
multiple: false
56 changes: 32 additions & 24 deletions src/resolver_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,52 @@ pub fn parallel_resolver_all(args: &mut Args) -> Result<()> {
]);
for (target, resolv_data) in &data {
if !resolv_data.ip.is_empty() {
let mut services_table = Table::new();
for port_data in &resolv_data.ports_data {
services_table
.add_row(row![bc => &format!("PORT => {}", port_data.portid.clone())]);
services_table.add_row(
if args.raw_output {
for port_data in &resolv_data.ports_data {
println!("{},{},{}", target, resolv_data.ip, port_data.portid)
}
} else {
let mut services_table = Table::new();
for port_data in &resolv_data.ports_data {
services_table
.add_row(row![bc => &format!("PORT => {}", port_data.portid.clone())]);
services_table.add_row(
row![c => &format!("SERVICE: {}", port_data.service.clone().unwrap_or_default().name)],
);
services_table.add_row(row![c => &format!("VERSION: {}" ,port_data
services_table.add_row(row![c => &format!("VERSION: {}" ,port_data
.service.clone().unwrap_or_default()
.version
.clone()
.unwrap_or_else(|| "NULL".to_string()))]);
services_table.add_row(row![c => &format!("PRODUCT: {}", port_data
services_table.add_row(row![c => &format!("PRODUCT: {}", port_data
.service.clone().unwrap_or_default()
.product
.clone()
.unwrap_or_else(|| "NULL".to_string()))]);
services_table.add_row(row![c => &format!("OS TYPE: {}", port_data
services_table.add_row(row![c => &format!("OS TYPE: {}", port_data
.service.clone().unwrap_or_default()
.ostype
.clone()
.unwrap_or_else(|| "NULL".to_string()))]);
services_table.add_row(row![c => &format!("EXTRA INFO: {}", port_data
services_table.add_row(row![c => &format!("EXTRA INFO: {}", port_data
.service.clone().unwrap_or_default()
.extrainfo
.clone()
.unwrap_or_else(|| "NULL".to_string()))]);
}
table.add_row(row![ d =>
target,
logic::null_ip_checker(&resolv_data.ip),
logic::return_ports_string(
&resolv_data
.ports_data
.iter()
.map(|f| f.portid.clone())
.collect(),
),
services_table,
]);
}
table.add_row(row![ d =>
target,
logic::null_ip_checker(&resolv_data.ip),
logic::return_ports_string(
&resolv_data
.ports_data
.iter()
.map(|f| f.portid.clone())
.collect(),
),
services_table,
]);
}
}

Expand All @@ -121,7 +127,7 @@ pub fn parallel_resolver_all(args: &mut Args) -> Result<()> {
args.file_name
)
}
if !args.quiet_flag {
if !args.quiet_flag && !args.raw_output {
table.printstd();
}

Expand All @@ -132,7 +138,9 @@ pub fn parallel_resolver_all(args: &mut Args) -> Result<()> {
);
info!("Logfile saved in {}\n\n", args.file_name);
}
println!();
if !args.quiet_flag {
println!();
}
Ok(())
}

Expand Down Expand Up @@ -174,7 +182,7 @@ fn parallel_resolver_engine(args: &Args, targets: HashSet<String>) -> HashMap<St
.unwrap_or_default()
.port
.retain(|f| f.state.state == "open");
if !args.keep_nmap_logs && std::fs::remove_file(&filename).is_err() {
if args.no_keep_nmap_logs && std::fs::remove_file(&filename).is_err() {
error!("Error removing filename {}.", &filename)
}
(ip.clone(), nmap_data)
Expand Down
3 changes: 2 additions & 1 deletion src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ pub struct Args {
pub quiet_flag: bool,
pub custom_resolvers: bool,
pub custom_ports_range: bool,
pub keep_nmap_logs: bool,
pub no_keep_nmap_logs: bool,
pub raw_output: bool,
pub fast_scan: bool,
pub files: Vec<String>,
pub resolvers: Vec<String>,
Expand Down

0 comments on commit f20f6d6

Please # to comment.