Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/tinyscanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
},
}
};

Expand All @@ -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);
Expand All @@ -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;
Expand Down