Skip to content

Commit b19ff1a

Browse files
authored
Merge pull request #17 from shellrow/dev
Release v0.9.0
2 parents 7e3441d + e74de8f commit b19ff1a

File tree

13 files changed

+125
-448
lines changed

13 files changed

+125
-448
lines changed

Cargo.toml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ntap"
3-
version = "0.8.0"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["shellrow <shellrow@foctal.com>"]
66
description = "Network traffic monitor/analyzer"
@@ -19,9 +19,9 @@ serde = { version = "1", features = ["derive"] }
1919
serde_json = "1"
2020
tracing = { version = "0.1" }
2121
tracing-subscriber = { version = "0.3", features = ["time", "chrono"] }
22-
netdev = { version = "0.36", features = ["serde"] }
23-
nex = { version = "0.22", features = ["serde"] }
24-
tokio = { version = "1.38" }
22+
netdev = { version = "0.37", features = ["serde"] }
23+
nex = { version = "0.23", features = ["serde"] }
24+
tokio = { version = "1" }
2525
clap = { version = "4.5", features = ["cargo"] }
2626
crossterm = "0.27"
2727
rand = "0.8"
@@ -30,22 +30,19 @@ comfy-table = "7.1"
3030
hickory-resolver = { version = "0.24" }
3131
futures = {version = "0.3"}
3232
netsock = { version = "0.3", features = ["serde"] }
33-
#reqwest = { version="0.12", default-features = false, features = ["json", "rustls-tls", "stream"] }
3433
chrono = { version = "0.4", features = ["serde"] }
35-
time = { version = "0.3", features = ["local-offset"] }
3634
ipnet = { version = "2.11" }
3735
home = "0.5"
3836
termtree = "0.5"
3937
indicatif = { version = "0.18" }
4038
inquire = "0.6"
41-
#ndb-oui = { version = "0.2", features = ["bundled"] }
42-
ndb-tcp-service = { version = "0.2", features = ["bundled"] }
43-
ndb-udp-service = { version = "0.2", features = ["bundled"] }
44-
ndb-as = { version = "0.2", features = ["bundled"] }
45-
ndb-ipv4-asn = { version = "0.2", features = ["bundled"] }
46-
ndb-ipv6-asn = { version = "0.2", features = ["bundled"] }
47-
ndb-ipv4-country = { version = "0.2", features = ["bundled"] }
48-
ndb-ipv6-country = { version = "0.2", features = ["bundled"] }
39+
ndb-tcp-service = { version = "0.3", features = ["bundled"] }
40+
ndb-udp-service = { version = "0.3", features = ["bundled"] }
41+
ndb-as = { version = "0.3", features = ["bundled"] }
42+
ndb-ipv4-asn = { version = "0.3", features = ["bundled"] }
43+
ndb-ipv6-asn = { version = "0.3", features = ["bundled"] }
44+
ndb-ipv4-country = { version = "0.3", features = ["bundled"] }
45+
ndb-ipv6-country = { version = "0.3", features = ["bundled"] }
4946

5047
[target.'cfg(windows)'.dependencies]
5148
winreg = "0.50"

resources/doc/USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ ntap [OPTIONS] [COMMAND]
1212
```
1313

1414
## Default Behavior
15-
By default, if no subcommand is specified, ntap enters the `stat` mode, which displays continuous network statistics:
15+
By default, if no subcommand is specified, ntap enters the `monitor` mode, which displays live network usage statistics:
1616
```bash
1717
ntap
1818
```
19-
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.
19+
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.
2020

2121
## Commands
2222

src/db/ip.rs

Whitespace-only changes.

src/db/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use anyhow::Result;
2-
//use ndb_oui::OuiDb;
32
use ndb_as::AsDb;
43
use ndb_ipv4_asn::Ipv4AsnDb;
54
use ndb_ipv4_country::Ipv4CountryDb;
@@ -9,10 +8,6 @@ use ndb_tcp_service::TcpServiceDb;
98
use ndb_udp_service::UdpServiceDb;
109
use std::sync::{OnceLock, RwLock};
1110

12-
//pub mod oui;
13-
//pub mod service;
14-
15-
//pub static OUI_DB: OnceLock<RwLock<OuiDb>> = OnceLock::new();
1611
pub static TCP_SERVICE_DB: OnceLock<RwLock<TcpServiceDb>> = OnceLock::new();
1712
pub static UDP_SERVICE_DB: OnceLock<RwLock<UdpServiceDb>> = OnceLock::new();
1813
pub static AS_DB: OnceLock<RwLock<AsDb>> = OnceLock::new();
@@ -26,7 +21,6 @@ pub fn init_databases() -> Result<()> {
2621
tracing::info!("Initializing databases...");
2722
init_tcp_service_db()?;
2823
init_udp_service_db()?;
29-
//init_oui_db()?;
3024
init_as_db()?;
3125
init_ipv4_asn_db()?;
3226
init_ipv6_asn_db()?;
@@ -36,15 +30,6 @@ pub fn init_databases() -> Result<()> {
3630
Ok(())
3731
}
3832

39-
/* pub fn init_oui_db() -> Result<()> {
40-
// Initialize OUI database
41-
let oui_db = OuiDb::bundled();
42-
OUI_DB
43-
.set(RwLock::new(oui_db))
44-
.map_err(|_| anyhow::anyhow!("Failed to set OUI_DB in OnceLock"))?;
45-
Ok(())
46-
} */
47-
4833
pub fn init_tcp_service_db() -> Result<()> {
4934
// Initialize TCP Service database
5035
let tcp_service_db = TcpServiceDb::bundled();

src/db/oui.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/db/service.rs

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/handler/monitor.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,108 @@ pub fn monitor(app: &ArgMatches) -> Result<()> {
206206
)?;
207207
Ok(())
208208
}
209+
210+
pub fn monitor_default(app: &ArgMatches) -> Result<()> {
211+
// Check .ntap directory
212+
match crate::sys::get_config_dir_path() {
213+
Some(_config_dir) => {}
214+
None => {
215+
let err_msg = "Could not get config directory path";
216+
tracing::error!("{err_msg}");
217+
anyhow::bail!(err_msg);
218+
}
219+
}
220+
221+
// Check dependencies (Currently only for Windows)
222+
match crate::sys::check_deps() {
223+
Ok(_) => {}
224+
Err(e) => {
225+
tracing::error!("Error: {:?}", e);
226+
anyhow::bail!(e.to_string());
227+
}
228+
}
229+
230+
// Load AppConfig
231+
let mut config = AppConfig::load();
232+
233+
// Initialize logger
234+
crate::log::init_logger(&config)?;
235+
236+
// Initialize DB
237+
crate::db::init_databases()?;
238+
239+
if app.contains_id("tickrate") {
240+
config.display.tick_rate = *app.get_one("tickrate").unwrap_or(&1000);
241+
}
242+
243+
// Start threads
244+
let mut threads: Vec<thread::JoinHandle<()>> = vec![];
245+
246+
let netstat_strage: Arc<NetStatStrage> = Arc::new(NetStatStrage::new());
247+
let mut netstat_strage_socket = Arc::clone(&netstat_strage);
248+
let mut netstat_strage_ui = Arc::clone(&netstat_strage);
249+
250+
let target_interfaces: Vec<netdev::Interface>;
251+
if config.network.interfaces.is_empty() {
252+
target_interfaces = crate::net::interface::get_usable_interfaces();
253+
} else {
254+
target_interfaces =
255+
crate::net::interface::get_interfaces_by_name(&config.network.interfaces);
256+
}
257+
let mut pcap_thread_index = 0;
258+
let pcap_handlers = target_interfaces
259+
.iter()
260+
.map(|iface| {
261+
let mut netstat_strage_pcap = Arc::clone(&netstat_strage);
262+
let iface = iface.clone();
263+
let pcap_option = crate::net::pcap::PacketCaptureOptions::from_interface(&iface);
264+
let thread_name = format!("pcap-thread-{}", iface.name.clone());
265+
let pcap_thread = thread::Builder::new().name(thread_name.clone());
266+
let pcap_handler = pcap_thread.spawn(move || {
267+
crate::net::pcap::start_background_capture(
268+
pcap_option,
269+
&mut netstat_strage_pcap,
270+
iface,
271+
);
272+
});
273+
tracing::info!("start thread {}", thread_name);
274+
pcap_thread_index += 1;
275+
pcap_handler
276+
})
277+
.collect::<Vec<_>>();
278+
279+
let socket_handler = thread::spawn(move || {
280+
tracing::info!("start thread socket_info_update");
281+
crate::net::socket::start_socket_info_update(&mut netstat_strage_socket);
282+
});
283+
284+
for pcap_handler in pcap_handlers {
285+
match pcap_handler {
286+
Ok(handle) => {
287+
threads.push(handle);
288+
}
289+
Err(e) => {
290+
tracing::error!("Error: {:?}", e);
291+
}
292+
}
293+
}
294+
threads.push(socket_handler);
295+
296+
if config.network.reverse_dns {
297+
let mut netstat_strage_dns = Arc::clone(&netstat_strage);
298+
let dns_handler = thread::spawn(move || {
299+
tracing::info!("start thread dns_map_update");
300+
crate::net::dns::start_dns_map_update(&mut netstat_strage_dns);
301+
});
302+
threads.push(dns_handler);
303+
}
304+
305+
tracing::info!("start TUI, netstat_data_update");
306+
307+
crate::tui::monitor::terminal::run(
308+
config,
309+
app.contains_id("enhanced-graphics"),
310+
&mut netstat_strage_ui,
311+
)?;
312+
Ok(())
313+
}

0 commit comments

Comments
 (0)