11use crate :: httpclient:: { create_http_client, send_request} ;
2- use crate :: utils:: read_file;
2+ use crate :: utils:: { queue_to_csv , read_file, ScanInfo } ;
33use clap:: Parser ;
44use futures:: future:: join_all;
55use reqwest:: Client ;
66use std:: sync:: Arc ;
7+ use crossbeam:: queue:: SegQueue ;
78use tokio:: sync:: Semaphore ;
89use tokio:: task;
910
@@ -12,7 +13,7 @@ mod utils;
1213
1314#[ derive( Parser , Debug ) ]
1415#[ command(
15- version = "1.4 .0" ,
16+ version = "1.5 .0" ,
1617 about = "An efficient and fast url survival detection tool" ,
1718 long_about = "Efficient URL activity tester written in Rust. Fast, batch, and lightweight"
1819) ]
@@ -44,6 +45,10 @@ struct Args {
4445 /// Supported Proxy socks5, http, and https, Example: -x socks5://127.0.0.1:1080
4546 #[ arg( short = 'x' , long) ]
4647 proxy : Option < String > ,
48+
49+ /// Output is an csv document, Example: -o result.csv
50+ #[ arg( short = 'o' , long) ]
51+ output : Option < String > ,
4752}
4853
4954#[ tokio:: main]
@@ -59,10 +64,11 @@ async fn main() {
5964
6065 let path = args. path ;
6166 let proxy = args. proxy ;
67+ let seg_queue: Arc < SegQueue < ScanInfo > > = Arc :: new ( SegQueue :: new ( ) ) ;
6268
6369 if let Some ( url) = args. url {
6470 let client = create_http_client ( args. timeout , proxy) ;
65- let result = send_request ( client, & url, u16_vec, & path) . await ;
71+ let result = send_request ( client, & url, u16_vec, & path, & seg_queue ) . await ;
6672 match result {
6773 Ok ( result) => {
6874 if result != "" {
@@ -85,9 +91,10 @@ async fn main() {
8591 let client: Client = client. clone ( ) ;
8692 let u16_vec = u16_vec. clone ( ) ;
8793 let path = path. clone ( ) ;
94+ let seg_queue = Arc :: clone ( & seg_queue) ;
8895 futures. push ( task:: spawn ( async move {
8996 let permit = semaphore. acquire ( ) . await . unwrap ( ) ;
90- let result = send_request ( client, url. as_str ( ) , u16_vec, & path) . await ;
97+ let result = send_request ( client, url. as_str ( ) , u16_vec, & path, & seg_queue ) . await ;
9198 match result {
9299 Ok ( result) => {
93100 if result != "" {
@@ -100,6 +107,10 @@ async fn main() {
100107 } ) ) ;
101108 }
102109 join_all ( futures) . await ;
110+ // 保存结果为CSV
111+ if let Some ( output) = args. output {
112+ queue_to_csv ( & seg_queue, output. as_str ( ) ) . ok ( ) ;
113+ }
103114 }
104115 Err ( e) => {
105116 println ! ( "{}" , e)
0 commit comments