Skip to content

Commit d0fcb76

Browse files
committed
feat(main): add new crawling system and improvements
1 parent 084d25c commit d0fcb76

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

src/main.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use tokio::io::{AsyncWriteExt, BufWriter};
1111
use crate::config::{DatabaseConfig, MainConfig};
1212
use crate::logger::DefaultColor;
1313
use crate::manager::TaskManager;
14-
use crate::randomizer::{IpGenerator, IpType};
14+
use crate::randomizer::{IpGenerator, IpGeneratorBuilder, IpType};
15+
use crate::scanning::crawler;
1516
use crate::updater::GithubAPI;
1617

1718
mod updater;
@@ -24,6 +25,7 @@ mod database;
2425
mod config;
2526
mod cli;
2627
mod scanning;
28+
mod webapi;
2729

2830
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
2931

@@ -107,11 +109,20 @@ async fn main() -> Result<()> {
107109
}
108110

109111
cli::Commands::Crawl { cidr } => {
110-
let max_tasks = active_cfg.get_crawler_tasks();
112+
let active_cfg = MainConfig::get().expect("Config must be loaded");
111113
let ip_count = active_cfg.crawler.ips_per_iteration;
114+
let range_data = parse_user_cidr(cidr).await;
112115

113-
let range = parse_user_cidr(cidr).await;
114-
tasks::crawl(range, max_tasks, ip_count).await;
116+
let mut builder = IpGenerator::builder()
117+
.amount(ip_count)
118+
.ip_type(IpType::PublicOnly);
119+
120+
if let Some((ip, prefix)) = range_data {
121+
builder = builder.cidr(ip, prefix);
122+
}
123+
124+
let generator_config = builder.build();
125+
crawler::crawl(generator_config).await;
115126
}
116127

117128
cli::Commands::Scan { path } => {
@@ -124,8 +135,8 @@ async fn main() -> Result<()> {
124135
TaskManager::spawn("IP Generator", move |cancel_token| async move {
125136
let result: std::io::Result<()> = async {
126137
let mut builder = IpGenerator::builder()
127-
.ip_type(IpType::PublicOnly)
128-
.count(amount);
138+
.ip_type(IpType::PublicOnly) // TODO: Make it configurable
139+
.amount(amount);
129140

130141
if let Some(cidr_data) = cidr {
131142
builder = builder.cidr(cidr_data.0, cidr_data.1);
@@ -143,7 +154,7 @@ async fn main() -> Result<()> {
143154
}
144155

145156
let generator = builder.build();
146-
let file = File::create(path).await?; // TODO: NEVER TRUST USER INPUT
157+
let file = File::create(path).await?;
147158
let mut writer = BufWriter::new(file);
148159
let mut ip_stream = generator.generate();
149160

0 commit comments

Comments
 (0)