Skip to content

Commit f38a6a6

Browse files
committed
Small optimizations
1 parent a60619e commit f38a6a6

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/main.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
1414
use pnet::datalink;
1515

1616
use crate::args::{ScanOptions, OutputFormat};
17+
use crate::network::NetworkIterator;
1718
use crate::vendor::Vendor;
1819

1920
fn main() {
@@ -117,11 +118,7 @@ fn main() {
117118
break;
118119
}
119120

120-
// The random approach has one major drawback, compared with the native
121-
// network iterator exposed by 'ipnetwork': memory usage. Instead of
122-
// using a small memory footprint iterator, we have to store all IP
123-
// addresses in memory at once. This can cause problems on large ranges.
124-
let ip_addresses: Vec<IpAddr> = network::compute_ip_range(&ip_networks, &scan_options);
121+
let ip_addresses = NetworkIterator::new(&ip_networks, scan_options.randomize_targets);
125122
let source_ip = network::find_source_ip(selected_interface, scan_options.source_ipv4);
126123

127124
for ip_address in ip_addresses {
@@ -143,8 +140,8 @@ fn main() {
143140
let mut sleep_ms_mount: u64 = 0;
144141
while !finish_sleep.load(Ordering::Relaxed) && sleep_ms_mount < scan_options.timeout_ms {
145142

146-
thread::sleep(Duration::from_millis(500));
147-
sleep_ms_mount += 500;
143+
thread::sleep(Duration::from_millis(100));
144+
sleep_ms_mount += 100;
148145
}
149146
timed_out.store(true, Ordering::Relaxed);
150147

src/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::env;
12
use std::process;
23
use std::sync::Arc;
34

@@ -14,7 +15,7 @@ use crate::args::ScanOptions;
1415
* user. This approach only supports Linux-like systems (Ubuntu, Fedore, ...).
1516
*/
1617
pub fn is_root_user() -> bool {
17-
std::env::var("USER").unwrap_or_else(|_| String::from("")) == *"root"
18+
env::var("USER").unwrap_or_else(|_| String::from("")) == *"root"
1819
}
1920

2021
/**

0 commit comments

Comments
 (0)