@@ -91,9 +91,9 @@ fn main() {
9191 Duration :: from_millis ( opts. timeout . into ( ) ) ,
9292 opts. tries ,
9393 opts. greppable ,
94- PortStrategy :: pick ( & opts. range , opts. ports , opts. scan_order ) ,
94+ PortStrategy :: pick ( & opts. range , opts. clone ( ) . ports , opts. scan_order ) ,
9595 opts. accessible ,
96- opts. exclude_ports . unwrap_or_default ( ) ,
96+ opts. exclude_ports . clone ( ) . unwrap_or_default ( ) ,
9797 opts. udp ,
9898 opts. closed ,
9999 ) ;
@@ -142,63 +142,29 @@ fn main() {
142142 }
143143
144144 let mut script_bench = NamedTimer :: start ( "Scripts" ) ;
145- for ( ip, ports) in & open_ports_per_ip {
146- let vec_str_ports: Vec < String > = ports. iter ( ) . map ( ToString :: to_string) . collect ( ) ;
147-
148- // nmap port style is 80,443. Comma separated with no spaces.
149- let ports_str = vec_str_ports. join ( "," ) ;
150-
151- // if option scripts is none, no script will be spawned
152- if opts. greppable || opts. scripts == ScriptsRequired :: None {
153- println ! ( "{} -> [{}]" , & ip, ports_str) ;
154- continue ;
155- }
156- detail ! ( "Starting Script(s)" , opts. greppable, opts. accessible) ;
157-
158- // Run all the scripts we found and parsed based on the script config file tags field.
159- for mut script_f in scripts_to_run. clone ( ) {
160- // This part allows us to add commandline arguments to the Script call_format, appending them to the end of the command.
161- if !opts. command . is_empty ( ) {
162- let user_extra_args = & opts. command . join ( " " ) ;
163- debug ! ( "Extra args vec {:?}" , user_extra_args) ;
164- if script_f. call_format . is_some ( ) {
165- let mut call_f = script_f. call_format . unwrap ( ) ;
166- call_f. push ( ' ' ) ;
167- call_f. push_str ( user_extra_args) ;
168- output ! (
169- format!( "Running script {:?} on ip {}\n Depending on the complexity of the script, results may take some time to appear." , call_f, & ip) ,
170- opts. greppable,
171- opts. accessible
172- ) ;
173- debug ! ( "Call format {}" , call_f) ;
174- script_f. call_format = Some ( call_f) ;
175- }
176- }
177145
178- // Building the script with the arguments from the ScriptFile, and ip-ports.
179- let script = Script :: build (
180- script_f. path ,
181- * ip,
182- ports. clone ( ) ,
183- script_f. port ,
184- script_f. ports_separator ,
185- script_f. tags ,
186- script_f. call_format ,
187- ) ;
188- match script. run ( ) {
189- Ok ( script_result) => {
190- detail ! ( script_result. to_string( ) , opts. greppable, opts. accessible) ;
191- }
192- Err ( e) => {
193- warning ! ( & format!( "Error {e}" ) , opts. greppable, opts. accessible) ;
194- }
195- }
196- }
146+ print_summary ( open_ports_per_ip, & scripts_to_run, & opts) ;
147+ // We only print closed ports if the user requested it.
148+ if opts. closed {
149+ println ! ( "closed ports:" ) ;
150+ print_summary ( closed_ports_per_ip, & scripts_to_run, & opts) ;
197151 }
198152
199- // TODO:
200- println ! ( "closed ports:" ) ;
201- for ( ip, ports) in & closed_ports_per_ip {
153+ // To use the runtime benchmark, run the process as: RUST_LOG=info ./rustscan
154+ script_bench. end ( ) ;
155+ benchmarks. push ( script_bench) ;
156+ rustscan_bench. end ( ) ;
157+ benchmarks. push ( rustscan_bench) ;
158+ debug ! ( "Benchmarks raw {:?}" , benchmarks) ;
159+ info ! ( "{}" , benchmarks. summary( ) ) ;
160+ }
161+
162+ fn print_summary (
163+ ports_per_ip : HashMap < IpAddr , Vec < u16 > > ,
164+ scripts_to_run : & Vec < ScriptFile > ,
165+ opts : & Opts ,
166+ ) {
167+ for ( ip, ports) in & ports_per_ip {
202168 let vec_str_ports: Vec < String > = ports. iter ( ) . map ( ToString :: to_string) . collect ( ) ;
203169
204170 // nmap port style is 80,443. Comma separated with no spaces.
@@ -251,14 +217,6 @@ fn main() {
251217 }
252218 }
253219 }
254-
255- // To use the runtime benchmark, run the process as: RUST_LOG=info ./rustscan
256- script_bench. end ( ) ;
257- benchmarks. push ( script_bench) ;
258- rustscan_bench. end ( ) ;
259- benchmarks. push ( rustscan_bench) ;
260- debug ! ( "Benchmarks raw {:?}" , benchmarks) ;
261- info ! ( "{}" , benchmarks. summary( ) ) ;
262220}
263221
264222/// Prints the opening title of RustScan
0 commit comments