Skip to content

Commit

Permalink
add counting scanned ips
Browse files Browse the repository at this point in the history
  • Loading branch information
Chleba committed Dec 29, 2023
1 parent adef70d commit 2e2b093
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum Action {
Scan(Vec<WifiInfo>),
ModeChange(Mode),
PingIp(String),
CountIp,
CidrError,
}

Expand Down
36 changes: 30 additions & 6 deletions src/components/discovery.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use chrono::Timelike;
use cidr::Ipv4Cidr;
use color_eyre::eyre::Result;
use color_eyre::owo_colors::OwoColorize;
use dns_lookup::{lookup_addr, lookup_host};
use futures::future::join_all;
use itertools::Position;
Expand Down Expand Up @@ -34,6 +35,7 @@ pub struct Discovery {
scanning: bool,
scanned_ips: Vec<ScannedIp>,
ips_to_scan: Vec<Ipv4Addr>,
ip_num: i32,
input: Input,
cidr: Option<Ipv4Cidr>,
cidr_error: bool,
Expand All @@ -54,6 +56,7 @@ impl Discovery {
scanning: false,
scanned_ips: Vec::new(),
ips_to_scan: Vec::new(),
ip_num: 0,
input: Input::default().with_value(String::from("192.168.1.0/24")),
cidr: None,
cidr_error: false,
Expand Down Expand Up @@ -100,7 +103,10 @@ impl Discovery {
}

fn scan(&mut self) {

self.scanned_ips.clear();
self.ip_num = 0;

if let Some(cidr) = self.cidr {
let pool_size = 8;
let ips = self.get_ips(cidr);
Expand All @@ -123,8 +129,12 @@ impl Discovery {
tx.send(Action::PingIp(packet.get_real_dest().to_string()))
.unwrap();
}
Ok(_) => {}
Err(_) => {}
Ok(_) => {
tx.send(Action::CountIp).unwrap();
}
Err(_) => {
tx.send(Action::CountIp).unwrap();
}
}
};
task::spawn(closure())
Expand Down Expand Up @@ -182,11 +192,21 @@ impl Discovery {
let table = Table::new(rows)
.header(header)
.block(
Block::default()
.title("|Discovery|")
// Block::default()
Block::new()
.title(
ratatui::widgets::block::Title::from("|Discovery|".yellow())
.position(ratatui::widgets::block::Position::Top)
.alignment(Alignment::Right),
)
.title(
ratatui::widgets::block::Title::from(
String::from(format!("|{} ip scanned|", self.ip_num.to_string())).red(),
)
.position(ratatui::widgets::block::Position::Top)
.alignment(Alignment::Left),
)
.border_style(Style::default().fg(Color::Rgb(100, 100, 100)))
.title_style(Style::default().fg(Color::Yellow))
.title_alignment(Alignment::Right)
.borders(Borders::ALL)
.padding(Padding::new(1, 0, 1, 0)),
)
Expand Down Expand Up @@ -280,6 +300,10 @@ impl Component for Discovery {
self.process_ip(ip);
}

if let Action::CountIp = action {
self.ip_num += 1;
}

if let Action::CidrError = action {
self.cidr_error = true;
}
Expand Down

0 comments on commit 2e2b093

Please sign in to comment.