mirror of
https://github.com/house-of-vanity/rexec.git
synced 2025-07-07 00:54:06 +00:00
Added parallel DNS resolver.
This commit is contained in:
48
Cargo.lock
generated
48
Cargo.lock
generated
@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
@ -244,6 +244,31 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-deque"
|
||||||
|
version = "0.8.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-epoch",
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-epoch"
|
||||||
|
version = "0.9.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
@ -1029,6 +1054,26 @@ dependencies = [
|
|||||||
"getrandom",
|
"getrandom",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rayon"
|
||||||
|
version = "1.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
"rayon-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rayon-core"
|
||||||
|
version = "1.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-deque",
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.2.16"
|
version = "0.2.16"
|
||||||
@ -1079,6 +1124,7 @@ dependencies = [
|
|||||||
"massh",
|
"massh",
|
||||||
"openssl",
|
"openssl",
|
||||||
"question",
|
"question",
|
||||||
|
"rayon",
|
||||||
"regex",
|
"regex",
|
||||||
"whoami",
|
"whoami",
|
||||||
]
|
]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rexec"
|
name = "rexec"
|
||||||
version = "1.1.0"
|
version = "1.2.0"
|
||||||
readme = "https://github.com/house-of-vanity/rexec#readme"
|
readme = "https://github.com/house-of-vanity/rexec#readme"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Parallel SSH executor"
|
description = "Parallel SSH executor"
|
||||||
@ -14,6 +14,7 @@ authors = ["AB <gh@hexor.ru>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dns-lookup = "2.0.2"
|
dns-lookup = "2.0.2"
|
||||||
|
rayon = "1.10"
|
||||||
log = "0.4.0"
|
log = "0.4.0"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
massh = "0.6.3"
|
massh = "0.6.3"
|
||||||
|
53
src/main.rs
53
src/main.rs
@ -6,6 +6,7 @@ use std::fs::read_to_string;
|
|||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use colored::*;
|
use colored::*;
|
||||||
@ -15,6 +16,7 @@ use itertools::Itertools;
|
|||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use massh::{MasshClient, MasshConfig, MasshHostConfig, SshAuth};
|
use massh::{MasshClient, MasshConfig, MasshHostConfig, SshAuth};
|
||||||
use question::{Answer, Question};
|
use question::{Answer, Question};
|
||||||
|
use rayon::prelude::*;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
// Define args
|
// Define args
|
||||||
@ -187,8 +189,6 @@ fn main() {
|
|||||||
let matched_hosts: Vec<_> = hosts.into_iter().unique().collect();
|
let matched_hosts: Vec<_> = hosts.into_iter().unique().collect();
|
||||||
|
|
||||||
// Build MasshHostConfig hostnames list
|
// Build MasshHostConfig hostnames list
|
||||||
let mut massh_hosts: Vec<MasshHostConfig> = vec![];
|
|
||||||
let mut hosts_and_ips: HashMap<IpAddr, String> = HashMap::new();
|
|
||||||
if args.parallel != 100 {
|
if args.parallel != 100 {
|
||||||
warn!("Parallelism: {} thread{}", &args.parallel, {
|
warn!("Parallelism: {} thread{}", &args.parallel, {
|
||||||
if args.parallel != 1 {
|
if args.parallel != 1 {
|
||||||
@ -200,23 +200,42 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!("Matched hosts:");
|
info!("Matched hosts:");
|
||||||
for host in matched_hosts.iter() {
|
let resolved_ips = Arc::new(Mutex::new(Vec::<(String, IpAddr)>::new()));
|
||||||
let ip = match lookup_host(&host.name) {
|
|
||||||
Ok(ip) => ip[0],
|
matched_hosts.par_iter().for_each(|host| {
|
||||||
Err(_) => {
|
match lookup_host(&host.name) {
|
||||||
error!("{} couldn't be resolved.", &host.name.red());
|
Ok(ips) if !ips.is_empty() => {
|
||||||
continue;
|
let ip = ips[0];
|
||||||
|
|
||||||
|
info!("{} [{}]", &host.name, ip);
|
||||||
|
|
||||||
|
let mut results = resolved_ips.lock().unwrap();
|
||||||
|
results.push((host.name.clone(), ip));
|
||||||
}
|
}
|
||||||
};
|
Ok(_) => {
|
||||||
info!("{} [{}]", &host.name, ip);
|
error!("DNS resolved, but IP not found: {}", &host.name.red());
|
||||||
hosts_and_ips.insert(ip, host.name.clone());
|
}
|
||||||
massh_hosts.push(MasshHostConfig {
|
Err(_) => {
|
||||||
addr: ip,
|
error!("DNS resolve failed: {}", &host.name.red());
|
||||||
auth: None,
|
}
|
||||||
port: None,
|
}
|
||||||
user: None,
|
});
|
||||||
})
|
|
||||||
|
let mut hosts_and_ips: HashMap<IpAddr, String> = HashMap::new();
|
||||||
|
let mut massh_hosts: Vec<MasshHostConfig> = Vec::new();
|
||||||
|
|
||||||
|
if let Ok(results) = resolved_ips.lock() {
|
||||||
|
for (hostname, ip) in results.iter() {
|
||||||
|
hosts_and_ips.insert(*ip, hostname.clone());
|
||||||
|
massh_hosts.push(MasshHostConfig {
|
||||||
|
addr: *ip,
|
||||||
|
auth: None,
|
||||||
|
port: None,
|
||||||
|
user: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build MasshConfig using massh_hosts vector
|
// Build MasshConfig using massh_hosts vector
|
||||||
let config = MasshConfig {
|
let config = MasshConfig {
|
||||||
default_auth: SshAuth::Agent,
|
default_auth: SshAuth::Agent,
|
||||||
|
Reference in New Issue
Block a user