(fix): do not launch nmap scans if not valid IPs are found.

Fixes #12
This commit is contained in:
Eduard Tolosa 2025-04-07 16:10:42 +00:00
parent 3afaf475d0
commit 8b0c7fcb27
5 changed files with 70 additions and 60 deletions

2
.vscode/launch.json vendored
View file

@ -9,7 +9,7 @@
"request": "launch",
"name": "Debug",
"program": "${workspaceRoot}/target/debug/${workspaceRootFolderName}",
"args": "-f targets.txt -u log.csv --resolvers resolvers.txt --iport 1 --lport 10000 --min-rate 10",
"args": "-t useast1.sugarcrm.com --fast-scan",
"cwd": "${workspaceRoot}",
"sourceLanguages": [
"rust"

View file

@ -24,7 +24,13 @@ prettytable-rs = "0.8.0"
serde-xml-rs = "0.5.1"
chrono = "0.4.26"
clap = { version = "2.34.0", features = ["yaml"] }
config = { version = "0.11.0", features = ["yaml", "json", "toml", "hjson", "ini"] }
config = { version = "0.11.0", features = [
"yaml",
"json",
"toml",
"hjson",
"ini",
] }
failure = "0.1.8"
# https://github.com/bluejekyll/trust-dns/pull/1632

View file

@ -1,6 +1,5 @@
#[cfg(windows)]
extern crate atty;
#[cfg(feature = "chrono")]
extern crate chrono;
#[cfg(feature = "colored")]
extern crate colored;
@ -8,7 +7,6 @@ extern crate log;
#[cfg(windows)]
extern crate winapi;
#[cfg(feature = "chrono")]
use chrono::Local;
#[cfg(feature = "colored")]
use colored::*;
@ -45,7 +43,6 @@ impl Log for SimpleLogger {
record.level().to_string()
}
};
#[cfg(feature = "chrono")]
{
print!(
"\n{} [{}] {}",
@ -54,10 +51,6 @@ impl Log for SimpleLogger {
record.args()
);
}
#[cfg(not(feature = "chrono"))]
{
print!("\n[{}] {}", level_string, record.args());
}
}
}

View file

@ -9,7 +9,7 @@ pub fn validate_target(target: &str) -> bool {
!target.starts_with('.')
&& target.contains('.')
&& !target.contains(&SPECIAL_CHARS[..])
&& target.chars().all(|c| c.is_ascii())
&& target.is_ascii()
}
pub fn null_ip_checker(ip: &str) -> String {

View file

@ -220,15 +220,25 @@ fn parallel_resolver_engine(
nmap_ips.retain(|ip| {
!ip.is_empty()
&& ip.parse::<Ipv4Addr>().is_ok()
&& !ip.parse::<Ipv4Addr>().unwrap().is_private()
&& ip.parse::<Ipv4Addr>().is_ok()
});
if nmap_ips.is_empty() {
error!("No valid IPs found for scanning.\n");
std::process::exit(1)
} else {
let nmap_data: HashMap<String, Nmaprun> = nmap_ips
.par_iter()
.map(|ip| {
let filename = format!("{}/{}.xml", &args.logs_dir, &ip);
match nmap::get_nmap_data(&filename, ip, &args.min_rate, &args.ports, args.fast_scan) {
match nmap::get_nmap_data(
&filename,
ip,
&args.min_rate,
&args.ports,
args.fast_scan,
) {
Ok(nmap_data) => {
nmap_data
.host
@ -281,4 +291,5 @@ fn parallel_resolver_engine(
)
})
.collect()
}
}