added outfile option

Signed-off-by: spv <spv0x04@proton.me>
This commit is contained in:
spv 2024-07-25 21:23:29 +02:00
parent 9c4eaacaf4
commit 2e627e32a4
No known key found for this signature in database
GPG Key ID: A527CD7A0F9353D8
2 changed files with 16 additions and 9 deletions

View File

@ -1,6 +1,6 @@
use std::{time::{Duration, Instant}, sync::{Arc, RwLock}};
use std::{io::Write, sync::{Arc, RwLock}, time::{Duration, Instant}};
use crate::discord_invite::{DiscordInvite, DiscordInviteError};
use crate::{discord_invite::{DiscordInvite, DiscordInviteError}, Args};
use console::Term;
use getset::{Getters, MutGetters, Setters};
use rand::seq::IteratorRandom;
@ -24,7 +24,13 @@ impl Bruter {
}
}
pub fn start(mut self) -> anyhow::Result<()> {
pub fn start(mut self, args: Args) -> anyhow::Result<()> {
let mut outfile = std::fs::OpenOptions::new()
.write(true)
.append(true)
.create(true)
.open(args.outfile)
.unwrap();
let mut rng = rand::thread_rng();
for i in 0..self.iterations {
let string: String = random_string::generate(
@ -54,7 +60,8 @@ impl Bruter {
&inv.code,
start.elapsed().as_millis()
);
self.found_codes.push(inv);
self.found_codes.push(inv.clone());
outfile.write_fmt(format_args!("https://discord.gg/{}\n", inv.code)).unwrap();
}
}
}

View File

@ -12,18 +12,18 @@ pub mod tui;
#[derive(Parser, Debug, Clone)]
pub struct Args{
wordlist: PathBuf,
#[clap(default_value_t = 10)]
iterations: usize,
outfile: PathBuf,
iterations: Option<usize>,
}
fn main() -> anyhow::Result<()>{
let args = Args::parse();
let mut bruter = Bruter::new(args.iterations);
let mut bruter = Bruter::new(args.iterations.unwrap_or(10));
let mut codes = vec![];
for w in std::fs::read_to_string(args.wordlist).unwrap().split('\n'){
for w in std::fs::read_to_string(args.clone().wordlist).unwrap().split('\n'){
codes.push(w.to_string());
}
bruter.set_codes(codes);
Bruter::start(bruter).unwrap();
Bruter::start(bruter, args).unwrap();
Ok(())
}