Skip to content

Commit

Permalink
Performance improvement.
Browse files Browse the repository at this point in the history
DNS queries with a dot [.] at the end of the domain are cheaper, this small but significant change results in an important performance improvement.

Signed-off-by: Edu4rdSHL <[email protected]>
  • Loading branch information
Edu4rdSHL committed Oct 20, 2021
1 parent 41e80a9 commit 5d0443a
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,35 +158,38 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
buffer.lines().map(str::to_owned).collect()
};

futures::stream::iter(hosts.into_iter().map(|host| {
let resolver_fut = resolvers.ipv4_lookup(host.clone());
let trustable_resolver_fut = trustable_resolver.ipv4_lookup(host.clone());
let wildcard_ips = wildcard_ips.clone();
async move {
if let Ok(ip) = resolver_fut.await {
stream::iter(hosts)
.map(|host| {
let resolver_fut = resolvers.ipv4_lookup(host.clone() + ".");
let trustable_resolver_fut = trustable_resolver.ipv4_lookup(host.clone() + ".");
let wildcard_ips = wildcard_ips.clone();

async move {
let mut ips = HashSet::new();
if disable_double_check {
ips = ip
.into_iter()
.map(|x| x.to_string())
.collect::<HashSet<String>>();
} else if let Ok(ip) = trustable_resolver_fut.await {
ips = ip
.into_iter()
.map(|x| x.to_string())
.collect::<HashSet<String>>();
if let Ok(ip) = resolver_fut.await {
if disable_double_check {
ips = ip
.into_iter()
.map(|x| x.to_string())
.collect::<HashSet<String>>();
} else if let Ok(ip) = trustable_resolver_fut.await {
ips = ip
.into_iter()
.map(|x| x.to_string())
.collect::<HashSet<String>>();
}
}
if show_ip_adress && !ips.iter().all(|ip| wildcard_ips.contains(ip)) {
println!("{};{:?}", host, ips)
} else if !ips.iter().all(|ip| wildcard_ips.contains(ip)) {
println!("{}", host)
}
}
}
}))
.buffer_unordered(threads)
.collect::<Vec<()>>()
.await;
})
.buffer_unordered(threads)
.collect::<Vec<()>>()
.await;

Ok(())
}

Expand Down

0 comments on commit 5d0443a

Please sign in to comment.