Skip to content

Commit

Permalink
Add support from reading from stdin.
Browse files Browse the repository at this point in the history
Signed-off-by: Edu4rdSHL <edu4rdshl@protonmail.com>
  • Loading branch information
Edu4rdSHL committed May 11, 2021
1 parent 177e29a commit ba1f7da
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/args.rs
Expand Up @@ -58,6 +58,7 @@ pub fn get_args() -> Args {
no_keep_nmap_logs: matches.is_present("no-keep-nmap-logs"),
raw_output: matches.is_present("raw-output"),
url_output: matches.is_present("url-output"),
from_stdin: matches.is_present("stdin"),
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: 11 additions & 0 deletions src/cli.yml
Expand Up @@ -13,6 +13,7 @@ args:
multiple: false
conflicts_with:
- files
- stdin

- files:
short: f
Expand All @@ -22,6 +23,7 @@ args:
multiple: true
conflicts_with:
- target
- stdin

- output:
short: o
Expand Down Expand Up @@ -100,3 +102,12 @@ args:
multiple: false
conflicts_with:
- raw-output

- stdin:
help: Read from stdin instead of files or aguments.
long: stdin
takes_value: false
multiple: false
conflicts_with:
- files
- target
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -11,11 +11,11 @@ pub mod args;
pub mod errors;
pub mod files;
pub mod logger;
pub mod misc;
pub mod resolver_engine;

mod defaults;
mod logic;
mod misc;
mod networking;
mod nmap;
mod structs;
8 changes: 5 additions & 3 deletions src/main.rs
@@ -1,7 +1,7 @@
use {
log::{error, Level},
std::{collections::HashSet, iter::FromIterator},
unimap::{args, errors::*, files::return_file_targets, logger, resolver_engine},
unimap::{args, errors::*, files::return_file_targets, logger, misc, resolver_engine},
};

fn run() -> Result<()> {
Expand All @@ -14,8 +14,10 @@ fn run() -> Result<()> {
if !arguments.files.is_empty() {
arguments.targets =
HashSet::from_iter(return_file_targets(&arguments, arguments.files.clone()))
} else {
} else if !arguments.target.is_empty() {
arguments.targets.insert(arguments.target.clone());
} else {
arguments.targets = misc::read_stdin()
}

if arguments.targets.len() < 50 {
Expand All @@ -27,7 +29,7 @@ fn run() -> Result<()> {
.build_global()
.unwrap();

if !arguments.target.is_empty() || !arguments.files.is_empty() {
if !arguments.targets.is_empty() {
resolver_engine::parallel_resolver_all(&mut arguments)
} else {
error!("Error: Target is empty or invalid!\n");
Expand Down
14 changes: 13 additions & 1 deletion src/misc.rs
@@ -1,4 +1,7 @@
use std::collections::HashSet;
use std::{
collections::HashSet,
io::{self, Read},
};

pub fn sanitize_target_string(target: String) -> String {
target
Expand Down Expand Up @@ -32,3 +35,12 @@ pub fn return_matches_hashset(matches: &clap::ArgMatches, value: &str) -> HashSe
HashSet::new()
}
}

pub fn read_stdin() -> HashSet<String> {
let mut buffer = String::new();
let mut stdin = io::stdin();
stdin
.read_to_string(&mut buffer)
.expect("Error getting input list.");
buffer.lines().map(str::to_owned).collect()
}
1 change: 1 addition & 0 deletions src/structs.rs
Expand Up @@ -22,6 +22,7 @@ pub struct Args {
pub raw_output: bool,
pub fast_scan: bool,
pub url_output: bool,
pub from_stdin: bool,
pub files: Vec<String>,
pub resolvers: Vec<String>,
pub targets: HashSet<String>,
Expand Down

0 comments on commit ba1f7da

Please sign in to comment.