Add support from reading from stdin.

Signed-off-by: Edu4rdSHL <edu4rdshl@protonmail.com>
This commit is contained in:
Edu4rdSHL 2021-05-11 15:00:50 -05:00
parent 177e29abe4
commit ba1f7da885
No known key found for this signature in database
GPG key ID: 3A574A4009F553E5
6 changed files with 32 additions and 5 deletions

View file

@ -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") {

View file

@ -13,6 +13,7 @@ args:
multiple: false
conflicts_with:
- files
- stdin
- files:
short: f
@ -22,6 +23,7 @@ args:
multiple: true
conflicts_with:
- target
- stdin
- output:
short: o
@ -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

View file

@ -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;

View file

@ -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<()> {
@ -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 {
@ -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");

View file

@ -1,4 +1,7 @@
use std::collections::HashSet;
use std::{
collections::HashSet,
io::{self, Read},
};
pub fn sanitize_target_string(target: String) -> String {
target
@ -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()
}

View file

@ -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>,