Skip to content

Commit

Permalink
feat: add ports scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
Chleba committed May 13, 2024
1 parent a8fe803 commit 35ef4da
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 252 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
debug/
target/

demo.tape

# These are backup files generated by rustfmt
**/*.rs.bk

Expand Down
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub enum Action {
CountIp,
CidrError,
PacketDump(DateTime<Local>, PacketsInfoTypesEnum, PacketTypeEnum),
PortScan(usize, u16),
PortScanDone(usize),
}

impl<'de> Deserialize<'de> for Action {
Expand Down
2 changes: 2 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl App {
let tabs = Tabs::default();
let discovery = Discovery::default();
let packetdump = PacketDump::default();
let ports = Ports::default();
let config = Config::new()?;

let mode = Mode::Normal;
Expand All @@ -57,6 +58,7 @@ impl App {
Box::new(tabs),
Box::new(discovery),
Box::new(packetdump),
Box::new(ports),
],
should_quit: false,
should_suspend: false,
Expand Down
28 changes: 13 additions & 15 deletions src/components/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const SPINNER_SYMBOLS: [&str; 6] = ["⠷", "⠯", "⠟", "⠻", "⠽", "⠾"];

#[derive(Clone)]
pub struct ScannedIp {
ip: String,
mac: String,
hostname: String,
vendor: String,
pub ip: String,
pub mac: String,
pub hostname: String,
pub vendor: String,
}

pub struct Discovery {
Expand Down Expand Up @@ -230,14 +230,12 @@ impl Discovery {

if let Some(oui) = &self.oui {
let oui_res = oui.lookup_by_mac(&n.mac);
match oui_res {
Ok(e) => {
if let Some(oui_res) = e {
// match oui_res {
if let Ok(oui_res) = oui_res {
if let Some(oui_res) = oui_res {
let cn = oui_res.company_name.clone();
n.vendor = cn;
}
}
Err(_) => {}
}
}
}
Expand Down Expand Up @@ -266,7 +264,7 @@ impl Discovery {
self.scanned_ips.sort_by(|a, b| {
let a_ip: Ipv4Addr = a.ip.parse::<Ipv4Addr>().unwrap();
let b_ip: Ipv4Addr = b.ip.parse::<Ipv4Addr>().unwrap();
return a_ip.partial_cmp(&b_ip).unwrap();
a_ip.partial_cmp(&b_ip).unwrap()
});
}

Expand All @@ -286,7 +284,7 @@ impl Discovery {

fn set_scrollbar_height(&mut self) {
let mut ip_len = 0;
if self.scanned_ips.len() > 0 {
if !self.scanned_ips.is_empty() {
ip_len = self.scanned_ips.len() - 1;
}
self.scrollbar_state = self.scrollbar_state.content_length(ip_len);
Expand All @@ -296,10 +294,10 @@ impl Discovery {
let index = match self.table_state.selected() {
Some(index) => {
if index == 0 {
if self.scanned_ips.len() > 0 {
self.scanned_ips.len() - 1
} else {
if self.scanned_ips.is_empty() {
0
} else {
self.scanned_ips.len() - 1
}
} else {
index - 1
Expand All @@ -315,7 +313,7 @@ impl Discovery {
let index = match self.table_state.selected() {
Some(index) => {
let mut s_ip_len = 0;
if self.scanned_ips.len() > 0 {
if !self.scanned_ips.is_empty() {
s_ip_len = self.scanned_ips.len() - 1;
}
if index >= s_ip_len {
Expand Down
30 changes: 17 additions & 13 deletions src/components/packetdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ use tokio::{
use super::{Component, Frame};
use crate::{
action::Action,
config::DEFAULT_BORDER_STYLE,
config::{Config, KeyBindings},
enums::{
ARPPacketInfo, ICMP6PacketInfo, ICMPPacketInfo, PacketTypeEnum, PacketsInfoTypesEnum,
TCPPacketInfo, TabsEnum, UDPPacketInfo,
},
layout::get_vertical_layout,
utils::MaxSizeVec,
config::DEFAULT_BORDER_STYLE,
};
use strum::{EnumCount, IntoEnumIterator};

Expand Down Expand Up @@ -493,10 +493,14 @@ impl PacketDump {
let index = match self.table_state.selected() {
Some(index) => {
let logs = self.get_array_by_packet_type(self.packet_type);
if index >= logs.len() - 1 {
if logs.is_empty() {
0
} else {
index + 1
if index >= logs.len() - 1 {
0
} else {
index + 1
}
}
}
None => 0,
Expand Down Expand Up @@ -847,7 +851,7 @@ impl PacketDump {
)
.border_style(Style::default().fg(Color::Rgb(100, 100, 100)))
.borders(Borders::ALL) // .padding(Padding::new(1, 0, 2, 0)),
.border_type(DEFAULT_BORDER_STYLE)
.border_type(DEFAULT_BORDER_STYLE),
)
.highlight_symbol(Span::styled(
String::from(char::from_u32(0x25b6).unwrap_or('>')),
Expand Down Expand Up @@ -909,15 +913,15 @@ impl Component for PacketDump {
self.table_state.select(Some(0));
self.set_scrollbar_height();
}
}
// -- dumping toggle
if let Action::DumpToggle = action {
if self.dump_paused.load(Ordering::Relaxed) {
self.dump_paused.store(false, Ordering::Relaxed);
self.start_loop();
} else {
self.dump_paused.store(true, Ordering::Relaxed);
self.loop_thread = None;
// -- dumping toggle
if let Action::DumpToggle = action {
if self.dump_paused.load(Ordering::Relaxed) {
self.dump_paused.store(false, Ordering::Relaxed);
self.start_loop();
} else {
self.dump_paused.store(true, Ordering::Relaxed);
self.loop_thread = None;
}
}
}
// -- packet recieved
Expand Down
Loading

0 comments on commit 35ef4da

Please sign in to comment.