Skip to content

Commit

Permalink
feat: add port's service name to a port number
Browse files Browse the repository at this point in the history
  • Loading branch information
Chleba committed Sep 4, 2024
1 parent 81e0e8a commit 931ea0b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
19 changes: 15 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ libc = "0.2.155"
log = "0.4.20"
mac_oui = { version = "0.4.8", features = ["with-db"] }
pnet = "0.34.0"
port-desc = "0.1.1"
pretty_assertions = "1.4.0"
rand = "0.8.5"
ratatui = { version = "0.26.1", features = ["serde", "macros"] }
Expand Down
20 changes: 14 additions & 6 deletions src/components/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use pnet::packet::{
use ratatui::style::Stylize;

use core::str;
use port_desc::{PortDescription, TransportProtocol};
use ratatui::{prelude::*, widgets::*};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::{string, time::Duration};
Expand All @@ -27,17 +28,11 @@ use super::Component;
use crate::enums::COMMON_PORTS;
use crate::{
action::Action,
components::discovery::ScannedIp,
config::DEFAULT_BORDER_STYLE,
enums::{PortsScanState, TabsEnum},
layout::get_vertical_layout,
mode::Mode,
tui::Frame,
};
use crossterm::event::{KeyCode, KeyEvent};
use rand::random;
use tui_input::backend::crossterm::EventHandler;
use tui_input::Input;

static POOL_SIZE: usize = 64;
const SPINNER_SYMBOLS: [&str; 6] = ["⠷", "⠯", "⠟", "⠻", "⠽", "⠾"];
Expand All @@ -56,6 +51,7 @@ pub struct Ports {
list_state: ListState,
scrollbar_state: ScrollbarState,
spinner_index: usize,
port_desc: Option<PortDescription>,
}

impl Default for Ports {
Expand All @@ -66,13 +62,19 @@ impl Default for Ports {

impl Ports {
pub fn new() -> Self {
let mut port_desc = None;
if let Ok(pd) = PortDescription::default() {
port_desc = Some(pd);
}

Self {
active_tab: TabsEnum::Discovery,
action_tx: None,
ip_ports: Vec::new(),
list_state: ListState::default().with_selected(Some(0)),
scrollbar_state: ScrollbarState::new(0),
spinner_index: 0,
port_desc,
}
}

Expand Down Expand Up @@ -210,6 +212,12 @@ impl Ports {
} else {
for p in &ip.ports {
ports_spans.push(p.to_string().green());

if let Some(pd) = &self.port_desc {
let p_type = pd.get_port_service_name(p.to_owned(), TransportProtocol::Tcp);
ports_spans.push(format!("({})", p_type).to_string().light_magenta());
}

ports_spans.push(", ".yellow());
}
}
Expand Down

0 comments on commit 931ea0b

Please sign in to comment.