From 9dc4ccd190c7b41dd622d36586a797781ac2e731 Mon Sep 17 00:00:00 2001 From: aelmir || Sphinex0 Date: Sat, 31 Jan 2026 11:02:38 +0100 Subject: [PATCH] fix -S --- src/tinyscanner/mod.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/tinyscanner/mod.rs b/src/tinyscanner/mod.rs index da3b3e9..b32b73e 100644 --- a/src/tinyscanner/mod.rs +++ b/src/tinyscanner/mod.rs @@ -7,6 +7,7 @@ use indicatif::{ProgressBar, ProgressStyle}; use log::{debug, info}; use rand::Rng; use std::{ + io::ErrorKind, net::{IpAddr, SocketAddr, ToSocketAddrs}, sync::Arc, time::Duration, @@ -167,11 +168,11 @@ pub async fn run( let flags = tcp_packet.get_flags(); let status = if (flags & TcpFlags::SYN) != 0 && (flags & TcpFlags::ACK) != 0 { - "open" + "OPEN" } else if (flags & TcpFlags::RST) != 0 { - "closed" + "CLOSED" } else { - "filtered" + "FILTERED" }; let _ = tx_result.send(status); } @@ -225,7 +226,7 @@ pub async fn run( Result::Ok(Result::Ok(s)) => s.to_string(), _ => { pending_scans_task.remove(&src_port); - "filtered".to_string() + "FILTERED".to_string() } } } else { @@ -279,7 +280,20 @@ pub async fn run( "OPEN".to_string() } } - _ => "CLOSED".to_string(), + Result::Ok(Result::Err(err)) => match err.kind() { + ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset => { + "CLOSED".to_string() + } + _ => { + debug!("Unexpected error for port {}: {:?}", port, err); + "FILTERED".to_string() + } + }, + Result::Err(e) => { + dbg!(e); + dbg!("#####################################################"); + "FILTERED".to_string() + }, } }; @@ -294,17 +308,18 @@ pub async fn run( while let Some((port, status)) = results_rx.recv().await { pb.inc(1); + let status_upper = status.to_uppercase(); - let styled_line = if status.contains("OPEN") { + let styled_line = if status_upper.contains("OPEN") { open_count += 1; format!("Port {:<5} is {}", port, status.bold().bright_green()) - } else if status.contains("CLOSED") { + } else if status_upper.contains("CLOSED") { format!("Port {:<5} is {}", port, "CLOSED".bold().bright_red()) } else { format!("Port {:<5} is {}", port, "filtered".yellow()) }; - if status.contains("OPEN") { + if status_upper.contains("OPEN") { pb.set_message(format!("Port {}", port)); pb.suspend(|| { println_tx!(tx_ui, info!, "{}", styled_line); @@ -313,7 +328,7 @@ pub async fn run( println_tx!(tx_ui, debug!, "{}", styled_line); } - results.push(format!("Port {:<5}: {}", port, status.to_uppercase())); + results.push(format!("Port {:<5}: {}", port, status_upper)); if pb.position() == ports_len as u64 { break;