| 
					
				 | 
			
			
				@@ -1,66 +0,0 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-use std::{time::{UNIX_EPOCH, SystemTime}, process::Command}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-use anyhow::{Context, anyhow}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-use clap::Parser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-use rayon::prelude::{IntoParallelIterator, ParallelIterator}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-#[derive(Debug, Parser)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-struct Options { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    #[clap(short = 'n', long, default_value="1")] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pub count: u32, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    #[clap(short = 'e', long)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pub seed: Option<String>, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    #[clap(name = "args", last = true)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pub run_args: Vec<String>, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-fn main() -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    env_logger::init(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let opts = Options::parse(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return spawn_zmaps(opts); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-fn spawn_zmap(args: &[String], i: u32) -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let mut args = Vec::from(args); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    args.push(format!("--shard={}", i)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    args.push(format!("--cores=0,{},1",i+2)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    args.push(format!("-o/tmp/ips{}.csv", i)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let result = Command::new("zmap") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        .args(args) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        .spawn()? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        .wait()?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if result.success() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return Ok(()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } else if let Some(code) = result.code() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return Err(anyhow!("code: {}", code)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return Err(anyhow!("")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-fn spawn_zmaps(opts: Options) -> Result<(), anyhow::Error> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let seed = if let Some(seed) = opts.seed { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        seed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        SystemTime::now() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .duration_since(UNIX_EPOCH) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .context("Attempted to obtain UNIX timestamp for seed")? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .as_millis() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .to_string() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let mut args = opts.run_args.clone(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    args.push(format!("--seed={}", seed)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    args.push(format!("--shards={}", opts.count)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    (0..opts.count).into_par_iter().map(|i| { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        spawn_zmap(&args, i).context(format!("Shard {} encountered error", i)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }).reduce(|| Ok(()), Result::and)?; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    Ok(()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 |