Skip to content
Merged
Show file tree
Hide file tree
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
25 changes: 11 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntap"
version = "0.8.0"
version = "0.9.0"
edition = "2021"
authors = ["shellrow <shellrow@foctal.com>"]
description = "Network traffic monitor/analyzer"
Expand All @@ -19,9 +19,9 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["time", "chrono"] }
netdev = { version = "0.36", features = ["serde"] }
nex = { version = "0.22", features = ["serde"] }
tokio = { version = "1.38" }
netdev = { version = "0.37", features = ["serde"] }
nex = { version = "0.23", features = ["serde"] }
tokio = { version = "1" }
clap = { version = "4.5", features = ["cargo"] }
crossterm = "0.27"
rand = "0.8"
Expand All @@ -30,22 +30,19 @@ comfy-table = "7.1"
hickory-resolver = { version = "0.24" }
futures = {version = "0.3"}
netsock = { version = "0.3", features = ["serde"] }
#reqwest = { version="0.12", default-features = false, features = ["json", "rustls-tls", "stream"] }
chrono = { version = "0.4", features = ["serde"] }
time = { version = "0.3", features = ["local-offset"] }
ipnet = { version = "2.11" }
home = "0.5"
termtree = "0.5"
indicatif = { version = "0.18" }
inquire = "0.6"
#ndb-oui = { version = "0.2", features = ["bundled"] }
ndb-tcp-service = { version = "0.2", features = ["bundled"] }
ndb-udp-service = { version = "0.2", features = ["bundled"] }
ndb-as = { version = "0.2", features = ["bundled"] }
ndb-ipv4-asn = { version = "0.2", features = ["bundled"] }
ndb-ipv6-asn = { version = "0.2", features = ["bundled"] }
ndb-ipv4-country = { version = "0.2", features = ["bundled"] }
ndb-ipv6-country = { version = "0.2", features = ["bundled"] }
ndb-tcp-service = { version = "0.3", features = ["bundled"] }
ndb-udp-service = { version = "0.3", features = ["bundled"] }
ndb-as = { version = "0.3", features = ["bundled"] }
ndb-ipv4-asn = { version = "0.3", features = ["bundled"] }
ndb-ipv6-asn = { version = "0.3", features = ["bundled"] }
ndb-ipv4-country = { version = "0.3", features = ["bundled"] }
ndb-ipv6-country = { version = "0.3", features = ["bundled"] }

[target.'cfg(windows)'.dependencies]
winreg = "0.50"
Expand Down
4 changes: 2 additions & 2 deletions resources/doc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ ntap [OPTIONS] [COMMAND]
```

## Default Behavior
By default, if no subcommand is specified, ntap enters the `stat` mode, which displays continuous network statistics:
By default, if no subcommand is specified, ntap enters the `monitor` mode, which displays live network usage statistics:
```bash
ntap
```
This default mode captures packets on all available network interfaces and continuously displays live network statistics, providing a quick and easy way to monitor current network activity without the need for additional configuration.
This default mode captures packets on all available network interfaces and continuously displays live network usage, providing a quick and easy way to monitor current network activity without the need for additional configuration.

## Commands

Expand Down
Empty file removed src/db/ip.rs
Empty file.
15 changes: 0 additions & 15 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Result;
//use ndb_oui::OuiDb;
use ndb_as::AsDb;
use ndb_ipv4_asn::Ipv4AsnDb;
use ndb_ipv4_country::Ipv4CountryDb;
Expand All @@ -9,10 +8,6 @@ use ndb_tcp_service::TcpServiceDb;
use ndb_udp_service::UdpServiceDb;
use std::sync::{OnceLock, RwLock};

//pub mod oui;
//pub mod service;

//pub static OUI_DB: OnceLock<RwLock<OuiDb>> = OnceLock::new();
pub static TCP_SERVICE_DB: OnceLock<RwLock<TcpServiceDb>> = OnceLock::new();
pub static UDP_SERVICE_DB: OnceLock<RwLock<UdpServiceDb>> = OnceLock::new();
pub static AS_DB: OnceLock<RwLock<AsDb>> = OnceLock::new();
Expand All @@ -26,7 +21,6 @@ pub fn init_databases() -> Result<()> {
tracing::info!("Initializing databases...");
init_tcp_service_db()?;
init_udp_service_db()?;
//init_oui_db()?;
init_as_db()?;
init_ipv4_asn_db()?;
init_ipv6_asn_db()?;
Expand All @@ -36,15 +30,6 @@ pub fn init_databases() -> Result<()> {
Ok(())
}

/* pub fn init_oui_db() -> Result<()> {
// Initialize OUI database
let oui_db = OuiDb::bundled();
OUI_DB
.set(RwLock::new(oui_db))
.map_err(|_| anyhow::anyhow!("Failed to set OUI_DB in OnceLock"))?;
Ok(())
} */

pub fn init_tcp_service_db() -> Result<()> {
// Initialize TCP Service database
let tcp_service_db = TcpServiceDb::bundled();
Expand Down
36 changes: 0 additions & 36 deletions src/db/oui.rs

This file was deleted.

104 changes: 0 additions & 104 deletions src/db/service.rs

This file was deleted.

105 changes: 105 additions & 0 deletions src/handler/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,108 @@ pub fn monitor(app: &ArgMatches) -> Result<()> {
)?;
Ok(())
}

pub fn monitor_default(app: &ArgMatches) -> Result<()> {
// Check .ntap directory
match crate::sys::get_config_dir_path() {
Some(_config_dir) => {}
None => {
let err_msg = "Could not get config directory path";
tracing::error!("{err_msg}");
anyhow::bail!(err_msg);
}
}

// Check dependencies (Currently only for Windows)
match crate::sys::check_deps() {
Ok(_) => {}
Err(e) => {
tracing::error!("Error: {:?}", e);
anyhow::bail!(e.to_string());
}
}

// Load AppConfig
let mut config = AppConfig::load();

// Initialize logger
crate::log::init_logger(&config)?;

// Initialize DB
crate::db::init_databases()?;

if app.contains_id("tickrate") {
config.display.tick_rate = *app.get_one("tickrate").unwrap_or(&1000);
}

// Start threads
let mut threads: Vec<thread::JoinHandle<()>> = vec![];

let netstat_strage: Arc<NetStatStrage> = Arc::new(NetStatStrage::new());
let mut netstat_strage_socket = Arc::clone(&netstat_strage);
let mut netstat_strage_ui = Arc::clone(&netstat_strage);

let target_interfaces: Vec<netdev::Interface>;
if config.network.interfaces.is_empty() {
target_interfaces = crate::net::interface::get_usable_interfaces();
} else {
target_interfaces =
crate::net::interface::get_interfaces_by_name(&config.network.interfaces);
}
let mut pcap_thread_index = 0;
let pcap_handlers = target_interfaces
.iter()
.map(|iface| {
let mut netstat_strage_pcap = Arc::clone(&netstat_strage);
let iface = iface.clone();
let pcap_option = crate::net::pcap::PacketCaptureOptions::from_interface(&iface);
let thread_name = format!("pcap-thread-{}", iface.name.clone());
let pcap_thread = thread::Builder::new().name(thread_name.clone());
let pcap_handler = pcap_thread.spawn(move || {
crate::net::pcap::start_background_capture(
pcap_option,
&mut netstat_strage_pcap,
iface,
);
});
tracing::info!("start thread {}", thread_name);
pcap_thread_index += 1;
pcap_handler
})
.collect::<Vec<_>>();

let socket_handler = thread::spawn(move || {
tracing::info!("start thread socket_info_update");
crate::net::socket::start_socket_info_update(&mut netstat_strage_socket);
});

for pcap_handler in pcap_handlers {
match pcap_handler {
Ok(handle) => {
threads.push(handle);
}
Err(e) => {
tracing::error!("Error: {:?}", e);
}
}
}
threads.push(socket_handler);

if config.network.reverse_dns {
let mut netstat_strage_dns = Arc::clone(&netstat_strage);
let dns_handler = thread::spawn(move || {
tracing::info!("start thread dns_map_update");
crate::net::dns::start_dns_map_update(&mut netstat_strage_dns);
});
threads.push(dns_handler);
}

tracing::info!("start TUI, netstat_data_update");

crate::tui::monitor::terminal::run(
config,
app.contains_id("enhanced-graphics"),
&mut netstat_strage_ui,
)?;
Ok(())
}
Loading