Skip to content

Commit

Permalink
v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mon-ius committed Aug 18, 2024
1 parent c9a8fef commit 1b18df1
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 100 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Cargo.lock
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
secret.txt
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[package]
name = "aw"
version = "0.0.3"
version = "0.0.4"
edition = "2021"

[dependencies]
clap = { version = "4.5.15", features = ["derive"] }
tokio = { version = "1.39.2", default-features = false, features = ["rt", "sync"] }
tokio = { version = "1.39.2", default-features = false, features = ["rt-multi-thread", "rt"] }
reqwest = { version = "0.12.5", default-features = false, features = ["http2", "json", "rustls-tls"] }
serde_json = { version = "1.0.120", default-features = false, features = ["alloc"] }
serde = { version = "1.0.204", features = ["derive"] }
ring = { version = "0.17.8", default-features = false}
tokio-stream = "0.1.15"
indicatif = "0.17.8"
chrono = "0.4.38"
base64 = "0.22.1"
rand = "0.8.5"

[[bin]]
name = "aw"
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let _ = ld_::interface(cli.n);
println!("Processing time: {:?}", start_time.elapsed());
Ok(())
}
}
9 changes: 9 additions & 0 deletions src/client/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ pub fn get_key() -> String {
res
}

pub fn encode(raw: &str) -> String {
let secret = BASE64.encode(raw.as_bytes());
secret
}

pub fn decode(secret: &str) -> String {
let raw = BASE64.decode(secret).unwrap();
String::from_utf8(raw).unwrap()
}
53 changes: 53 additions & 0 deletions src/client/geo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use rand::Rng as _;
use std::net::Ipv4Addr;

pub fn generate_geo_ip() -> String {
let mut rng = rand::thread_rng();
Ipv4Addr::new(
rng.gen_range(1..=253),
rng.gen(),
rng.gen(),
rng.gen_range(1..=254)
).to_string()
}

pub fn generate_us_ip() -> String {
let mut rng = rand::thread_rng();
let _blocks = [
(3, 0, 0, 0, 4), // 3.0.0.0/8
(4, 0, 0, 0, 6), // 4.0.0.0/6
(8, 0, 0, 0, 7), // 8.0.0.0/7
(11, 0, 0, 0, 8), // 11.0.0.0/8
(12, 0, 0, 0, 6), // 12.0.0.0/6
(16, 0, 0, 0, 6), // 16.0.0.0/6
(20, 0, 0, 0, 7), // 20.0.0.0/7
(24, 0, 0, 0, 8), // 24.0.0.0/8
(26, 0, 0, 0, 7), // 26.0.0.0/7
(28, 0, 0, 0, 6), // 28.0.0.0/6
(32, 0, 0, 0, 3), // 32.0.0.0/3
(64, 0, 0, 0, 2), // 64.0.0.0/2
(128, 0, 0, 0, 3), // 128.0.0.0/3
(160, 0, 0, 0, 5), // 160.0.0.0/5
(168, 0, 0, 0, 6), // 168.0.0.0/6
(172, 0, 0, 0, 8), // 172.0.0.0/8
(173, 0, 0, 0, 8), // 173.0.0.0/8
(174, 0, 0, 0, 7), // 174.0.0.0/7
(184, 0, 0, 0, 6), // 184.0.0.0/6
(192, 0, 0, 0, 8), // 192.0.0.0/8
(198, 0, 0, 0, 7), // 198.0.0.0/7
(200, 0, 0, 0, 5), // 200.0.0.0/5
(208, 0, 0, 0, 4), // 208.0.0.0/4
];
let (base_a, _, _, _, mask) = _blocks[rng.gen_range(0.._blocks.len())];
let ip = match mask {
8 => Ipv4Addr::new(base_a, rng.gen(), rng.gen(), rng.gen()),
7 => Ipv4Addr::new(base_a, rng.gen(), rng.gen(), rng.gen()),
6 => Ipv4Addr::new(base_a + rng.gen_range(0..4), rng.gen(), rng.gen(), rng.gen()),
5 => Ipv4Addr::new(base_a + rng.gen_range(0..8), rng.gen(), rng.gen(), rng.gen()),
4 => Ipv4Addr::new(base_a + rng.gen_range(0..16), rng.gen(), rng.gen(), rng.gen()),
3 => Ipv4Addr::new(base_a + rng.gen_range(0..32), rng.gen(), rng.gen(), rng.gen()),
2 => Ipv4Addr::new(base_a + rng.gen_range(0..64), rng.gen(), rng.gen(), rng.gen()),
_ => Ipv4Addr::new(base_a, rng.gen(), rng.gen(), rng.gen()),
};
ip.to_string()
}
4 changes: 3 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ pub mod warp;
pub use warp::WARP;

pub mod date;
pub mod cipher;
pub mod cipher;
pub mod geo;
pub mod process;
261 changes: 261 additions & 0 deletions src/client/process.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
use tokio::time::Duration;
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};

const RETRY_DELAY: Duration = Duration::from_secs(120);
const CAPACITY: usize = 1000;
const MAX_SEED: usize = 2;
const _EPOOL: &str = "SVQ4azYxMm4tSDhDNDJFajYtODAyN0pFVHAgbzY3OXZjMEYtM1ZMVzFrNzQtY0YwOWE0N1AgMHkyYjNVejUtUGNrSDk3NTQtM202NEExcnUgN1AwM0VXMk0tTWdsMzEyYjYtNXU2QzJ5NHMgMnZ0RDlJNzQtN3R3MTBhVDQtRVk1NzB1NlEgc0MyNTRPVjEtNkIwTTgxenMtOFltN0paMTMgOUw1R0VzODAtOHVTM3g5ZTEtOW12WTU2N2EgN2wyM1RXNWYtdjZUNTI5S3ctMWRvMlJBMzQgZTdNWEUyMDktaXg1MElyMTItOHEzY2IxN3ogM1BGSDg1OXktYzUxNEo5cHItMkU5NE0xUlggN0thYjEwTzQtOU9sdlc4NDMtNTBucWg3MmkgM0o0bmZ2OTIteDUzTTRBOFctWGQxdjkyN2IgYWhHMFM4MzEtME1tNTEzQkotSzduNlQxNVcgSzk0N0ZPRzUtNjRsMHZESDIteTc4MzFwVmkgcjE0dDlKeTUtOTZRM2gxVnYtN040YWkwcDggTTRGM2Q2N0EtYlo5azBxNzIteVVSZTg5MjQgSUJTTDgyNDYtSTM1OWlMNnEtNXdYMmZsNDcgUDZFMzE4Yk4tN2JJMlIwUTgtNzJKOWZ1NFYgVDVEWjgzRzAtUm1BMTQ5N3ctODFYeVJZMzcgOGw1MER4YzEtWms4ajdhOTAtMndOOTMxb0U=";

use super::warp::WARP;
use super::cipher;
use super::geo;

pub async fn batch_create(num: usize) -> Vec<WARP> {
let mp = MultiProgress::new();
let create_style = ProgressStyle::with_template("[{elapsed_precise}] [{eta_precise}] {wide_bar:.cyan/green} {pos:>7}/{len:7}")
.unwrap()
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ ");

let mut tasks = Vec::new();
let mut warps = Vec::new();

for _ in 0..num {
let task = tokio::spawn(async {
let ip = geo::generate_us_ip();
WARP::build(ip).await
});

tasks.push(task);

if tasks.len() == CAPACITY {
let mut _tasks = vec![];
_tasks.append(&mut tasks);

let pb = mp.add(ProgressBar::new(_tasks.len() as u64));
pb.set_style(create_style.clone());

for task in _tasks {
if let Ok(Ok(warp)) = task.await {
warps.push(warp);
}
pb.inc(1);
}
tasks.clear();
pb.finish();
tokio::time::sleep(RETRY_DELAY).await;
}
}

let _pb = mp.add(ProgressBar::new(tasks.len() as u64));
_pb.set_style(create_style.clone());
for task in tasks {
if let Ok(Ok(warp)) = task.await {
warps.push(warp);
}
_pb.inc(1);
}
_pb.finish();
warps
}

pub async fn batch_seed(warp: Vec<WARP>) -> Vec<WARP> {
let mp = MultiProgress::new();
let seed_style = ProgressStyle::with_template("[{elapsed_precise}] [{eta_precise}] {wide_bar:.cyan/yellow} {pos:>7}/{len:7}")
.unwrap()
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ ");

let mut _warps = warp.clone();
let pool = cipher::decode(_EPOOL);
let seeds : Vec<_> = pool.split(" ").into_iter().collect();
let mut tasks = Vec::new();
let mut warps = Vec::new();

for _ in 0..MAX_SEED {
for seed in &seeds {
if let Some(warp) = _warps.pop() {
let seed = seed.to_string();
let task = tokio::spawn(async move {
warp.update_license(seed).await
});
tasks.push(task);
} else {
break;
}

if tasks.len() == CAPACITY {
tokio::time::sleep(RETRY_DELAY).await;
let mut _tasks = vec![];
_tasks.append(&mut tasks);

let pb = mp.add(ProgressBar::new(_tasks.len() as u64));
pb.set_style(seed_style.clone());

for task in _tasks {
if let Ok(Ok(warp)) = task.await {
warps.push(warp);
}
pb.inc(1);
}
tasks.clear();
pb.finish();
}
}
}

let _pb = mp.add(ProgressBar::new(tasks.len() as u64));
_pb.set_style(seed_style.clone());
for task in tasks {
if let Ok(Ok(warp)) = task.await {
warps.push(warp);
}
_pb.inc(1);
}
_pb.finish();
warps
}

pub async fn batch_update(warp: Vec<WARP>) -> Vec<WARP> {
let mp = MultiProgress::new();
let update_style = ProgressStyle::with_template("[{elapsed_precise}] [{eta_precise}] {wide_bar:.cyan/blue} {pos:>7}/{len:7}")
.unwrap()
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ ");

let mut tasks = Vec::new();
let mut warps = Vec::new();

for sw in warp{
let ss = sw.license();
let task = tokio::spawn(async move {
sw.update_license(ss).await
});
tasks.push(task);

if tasks.len() == CAPACITY {
tokio::time::sleep(RETRY_DELAY).await;
let mut _tasks = vec![];
_tasks.append(&mut tasks);

let pb = mp.add(ProgressBar::new(_tasks.len() as u64));
pb.set_style(update_style.clone());

for task in _tasks {
if let Ok(Ok(warp)) = task.await {
warps.push(warp);
}
pb.inc(1);
}
tasks.clear();
pb.finish();
}
}

let _pb = mp.add(ProgressBar::new(tasks.len() as u64));
_pb.set_style(update_style.clone());
for task in tasks {
if let Ok(Ok(warp)) = task.await {
warps.push(warp);
}
_pb.inc(1);
}
_pb.finish();

warps
}

pub async fn batch_delete(warp: Vec<WARP>) -> Vec<WARP> {
let mp = MultiProgress::new();
let delete_style = ProgressStyle::with_template("[{elapsed_precise}] [{eta_precise}] {wide_bar:.cyan/red} {pos:>7}/{len:7}")
.unwrap()
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ ");

let mut tasks = Vec::new();
let mut warps = Vec::new();

for dw in warp{
let task = tokio::spawn(async move {
dw.delete().await
});
tasks.push(task);

if tasks.len() == CAPACITY {
tokio::time::sleep(RETRY_DELAY).await;
let mut _tasks = vec![];
_tasks.append(&mut tasks);

let pb = mp.add(ProgressBar::new(_tasks.len() as u64));
pb.set_style(delete_style.clone());

for task in _tasks {
if let Ok(Ok(warp)) = task.await {
warps.push(warp);
}
pb.inc(1);
}
tasks.clear();
pb.finish();
}
}

let _pb = mp.add(ProgressBar::new(tasks.len() as u64));
_pb.set_style(delete_style.clone());
for task in tasks {
if let Ok(Ok(warp)) = task.await {
warps.push(warp);
}
_pb.inc(1);
}
_pb.finish();

warps
}

pub async fn batch_info(warp: Vec<WARP>){
let mut tasks = Vec::new();

for _warp in warp{
let task = tokio::spawn(async move {
_warp.get_quota().await
});
tasks.push(task);
}

for task in tasks {
if let Ok(Ok(info)) = task.await {
println!("{:#?}", info);
}
}
}



// let _pb = mp.add(ProgressBar::new(seed_tasks.len() as u64));
// _pb.set_style(update_style.clone());
// for task in seed_tasks {
// if let Ok(Ok(warp)) = task.await {
// seed_warps.push(warp);
// }
// _pb.inc(1);
// }
// _pb.finish();

// tokio::time::sleep(RETRY_DELAY).await;
// let mut warps = Vec::new();
// let mut tasks = Vec::new();

// for sw in seed_warps{
// let ss = sw.license();
// let task = tokio::spawn(async move {
// sw.update_license(ss).await
// });
// tasks.push(task);
// }

// let _pb = mp.add(ProgressBar::new(tasks.len() as u64));
// _pb.set_style(update_style.clone());
// for task in tasks {
// if let Ok(Ok(warp)) = task.await {
// warps.push(warp);
// }
// _pb.inc(1);
// }
// _pb.finish();
Loading

0 comments on commit 1b18df1

Please sign in to comment.