mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2026-10-24 08:02:12 +00:00
feat: search by country
This commit is contained in:
parent
7745c22be1
commit
fc63f71b70
7 changed files with 120 additions and 12 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
|
@ -770,6 +770,18 @@ dependencies = [
|
|||
"libloading 0.7.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dns-lookup"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53ecafc952c4528d9b51a458d1a8904b81783feff9fde08ab6ed2545ff396872"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"socket2",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "downcast-rs"
|
||||
version = "1.2.0"
|
||||
|
|
@ -3255,10 +3267,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "sniffnet"
|
||||
version = "1.1.3"
|
||||
version = "1.1.4"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"confy",
|
||||
"dns-lookup",
|
||||
"etherparse",
|
||||
"iced",
|
||||
"iced_lazy",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "sniffnet"
|
||||
version = "1.1.3"
|
||||
version = "1.1.4"
|
||||
authors = ["Giuliano Bellini"]
|
||||
edition = "2021"
|
||||
description = "Application to comfortably monitor your network traffic"
|
||||
|
|
@ -40,6 +40,7 @@ confy = "0.5.1"
|
|||
serde = { version = "1.0.160", default_features = false, features = ["derive"] }
|
||||
rodio = { version = "0.17.1", default_features = false, features = ["mp3"] }
|
||||
reqwest = { version = "0.11.16", features = ["json", "blocking"] }
|
||||
dns-lookup = "1.0.8"
|
||||
|
||||
[dev-dependencies]
|
||||
rstest = "0.17.0"
|
||||
|
|
|
|||
|
|
@ -1,19 +1,26 @@
|
|||
use crate::gui::components::tab::get_pages_tabs;
|
||||
use crate::gui::styles::style_constants::{get_font, SARASA_MONO_SC_BOLD};
|
||||
use crate::gui::styles::types::element_type::ElementType;
|
||||
use crate::gui::styles::types::style_tuple::StyleTuple;
|
||||
use crate::gui::types::message::Message;
|
||||
use crate::{RunningPage, Sniffer};
|
||||
use iced::widget::{Column, Container};
|
||||
use iced::{Alignment, Length};
|
||||
use crate::networking::types::traffic_type::TrafficType;
|
||||
use crate::report::get_report_entries::{get_report_entries, get_searched_entries};
|
||||
use crate::utils::countries::{get_flag_from_country_code, FLAGS_WIDTH};
|
||||
use crate::utils::formatted_strings::get_connection_color;
|
||||
use crate::{Language, RunningPage, Sniffer, StyleType};
|
||||
use dns_lookup::lookup_addr;
|
||||
use iced::widget::{Column, Container, Row, Scrollable, Text, TextInput};
|
||||
use iced::{Alignment, Font, Length};
|
||||
use iced_native::widget::scrollable::Properties;
|
||||
|
||||
/// Computes the body of gui inspect page
|
||||
pub fn inspect_page(sniffer: &Sniffer) -> Container<Message> {
|
||||
//let font = get_font(sniffer.style);
|
||||
let font = get_font(sniffer.style);
|
||||
|
||||
let body = Column::new()
|
||||
let mut body = Column::new()
|
||||
.width(Length::Fill)
|
||||
.padding(5)
|
||||
.spacing(5)
|
||||
.padding(10)
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center);
|
||||
|
||||
let mut tab_and_body = Column::new().height(Length::Fill);
|
||||
|
|
@ -38,9 +45,74 @@ pub fn inspect_page(sniffer: &Sniffer) -> Container<Message> {
|
|||
|
||||
tab_and_body = tab_and_body.push(tabs);
|
||||
|
||||
body = body.push(search_bar(sniffer));
|
||||
let mut col_report = Column::new().height(Length::Fill).width(Length::Fill);
|
||||
col_report = col_report
|
||||
.push(Text::new(" Src IP address Src port Dst IP address Dst port Layer4 Layer7 Packets Bytes Country").font(font))
|
||||
.push(Text::new("--------------------------------------------------------------------------------------------------------------------------").font(font))
|
||||
;
|
||||
let mut scroll_report = Column::new();
|
||||
for key_val in get_searched_entries(&sniffer.info_traffic.clone(), sniffer.search.clone()) {
|
||||
let entry_color = get_connection_color(key_val.1.traffic_type, sniffer.style);
|
||||
let mut entry_row = Row::new().align_items(Alignment::Center).push(
|
||||
Text::new(format!(
|
||||
" {}{}",
|
||||
key_val.0.print_gui(),
|
||||
key_val.1.print_gui()
|
||||
))
|
||||
.style(iced::theme::Text::Color(entry_color))
|
||||
.font(SARASA_MONO_SC_BOLD),
|
||||
);
|
||||
if key_val.1.country.is_empty() {
|
||||
entry_row = entry_row
|
||||
.push(
|
||||
Text::new("?")
|
||||
.width(Length::Fixed(FLAGS_WIDTH))
|
||||
.style(iced::theme::Text::Color(entry_color))
|
||||
.font(SARASA_MONO_SC_BOLD),
|
||||
)
|
||||
.push(Text::new(" "));
|
||||
} else {
|
||||
entry_row = entry_row
|
||||
.push(get_flag_from_country_code(&key_val.1.country))
|
||||
.push(Text::new(" "));
|
||||
}
|
||||
// let address_to_lookup = match key_val.1.traffic_type {
|
||||
// TrafficType::Outgoing => &key_val.0.address2,
|
||||
// _ => &key_val.0.address1,
|
||||
// };
|
||||
// entry_row = entry_row.push(
|
||||
// Text::new(lookup_addr(&address_to_lookup.parse().unwrap()).unwrap()).font(font)
|
||||
// );
|
||||
scroll_report = scroll_report.push(entry_row);
|
||||
}
|
||||
col_report = col_report.push(Container::new(
|
||||
Scrollable::new(scroll_report)
|
||||
.horizontal_scroll(Properties::new())
|
||||
.style(<StyleTuple as Into<iced::theme::Scrollable>>::into(
|
||||
StyleTuple(sniffer.style, ElementType::Standard),
|
||||
)),
|
||||
));
|
||||
|
||||
body = body.push(col_report);
|
||||
|
||||
Container::new(Column::new().push(tab_and_body.push(body)))
|
||||
.height(Length::Fill)
|
||||
.style(<StyleTuple as Into<iced::theme::Container>>::into(
|
||||
StyleTuple(sniffer.style, ElementType::Standard),
|
||||
))
|
||||
}
|
||||
|
||||
fn search_bar(sniffer: &Sniffer) -> Container<'static, Message> {
|
||||
let font = get_font(sniffer.style);
|
||||
|
||||
let text_input = TextInput::new("AAA", &sniffer.search)
|
||||
.on_input(move |value| Message::Search(value))
|
||||
.padding([0, 0, 0, 10])
|
||||
.font(font)
|
||||
.width(Length::Fixed(100.0))
|
||||
.style(<StyleTuple as Into<iced::theme::TextInput>>::into(
|
||||
StyleTuple(sniffer.style, ElementType::Standard),
|
||||
));
|
||||
Container::new(text_input)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,6 @@ use crate::utils::formatted_strings::{
|
|||
};
|
||||
use crate::{AppProtocol, Language, ReportType, RunningPage, StyleType};
|
||||
|
||||
//use dns_lookup::lookup_addr;
|
||||
|
||||
/// Computes the body of gui overview page
|
||||
pub fn overview_page(sniffer: &Sniffer) -> Container<Message> {
|
||||
let font = get_font(sniffer.style);
|
||||
|
|
@ -380,7 +378,6 @@ fn lazy_col_packets(observed: u128, filtered: u128, sniffer: &Sniffer) -> Column
|
|||
let mut col_packets = Column::new()
|
||||
//.push(iced::Text::new(std::env::current_dir().unwrap().to_str().unwrap()).font(font))
|
||||
//.push(iced::Text::new(confy::get_configuration_file_path("sniffnet", None).unwrap().to_string_lossy()).font(font))
|
||||
//.push(Text::new(lookup_addr(&"8.8.8.8".parse().unwrap()).unwrap()).font(font))
|
||||
.push(
|
||||
Text::new(get_active_filters_string(
|
||||
&sniffer.filters.clone(),
|
||||
|
|
|
|||
|
|
@ -69,4 +69,6 @@ pub enum Message {
|
|||
ResetButtonPressed,
|
||||
/// Ctrl+D keys have been pressed
|
||||
CtrlDPressed,
|
||||
/// Update search parameters of inspect page
|
||||
Search(String),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ pub struct Sniffer {
|
|||
pub language: Language,
|
||||
/// Number of unread notifications
|
||||
pub unread_notifications: usize,
|
||||
/// Search parameters of inspect page
|
||||
pub search: String,
|
||||
}
|
||||
|
||||
impl Sniffer {
|
||||
|
|
@ -102,6 +104,7 @@ impl Sniffer {
|
|||
running_page: RunningPage::Overview,
|
||||
language: config_settings.language,
|
||||
unread_notifications: 0,
|
||||
search: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,6 +174,7 @@ impl Sniffer {
|
|||
Message::EscKeyPressed => return self.shortcut_esc(),
|
||||
Message::ResetButtonPressed => return self.reset_button_pressed(),
|
||||
Message::CtrlDPressed => return self.shortcut_ctrl_d(),
|
||||
Message::Search(parameters) => self.search = parameters,
|
||||
}
|
||||
Command::none()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,3 +39,22 @@ pub fn get_report_entries(
|
|||
.map(|e| (e.0.clone(), e.1.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_searched_entries(
|
||||
info_traffic: &Arc<Mutex<InfoTraffic>>,
|
||||
search: String,
|
||||
) -> Vec<(AddressPortPair, InfoAddressPortPair)> {
|
||||
let info_traffic_lock = info_traffic.lock().unwrap();
|
||||
let mut searched_vec: Vec<(&AddressPortPair, &InfoAddressPortPair)> = Vec::new();
|
||||
searched_vec = info_traffic_lock
|
||||
.map
|
||||
.iter()
|
||||
.filter(|(key, value)| value.country == search)
|
||||
.collect();
|
||||
|
||||
let n_entry = min(searched_vec.len(), 20);
|
||||
searched_vec[0..n_entry]
|
||||
.iter()
|
||||
.map(|e| (e.0.clone(), e.1.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue