@@ -91,9 +91,9 @@ fn main() {
91
91
Duration :: from_millis ( opts. timeout . into ( ) ) ,
92
92
opts. tries ,
93
93
opts. greppable ,
94
- PortStrategy :: pick ( & opts. range , opts. ports , opts. scan_order ) ,
94
+ PortStrategy :: pick ( & opts. range , opts. clone ( ) . ports , opts. scan_order ) ,
95
95
opts. accessible ,
96
- opts. exclude_ports . unwrap_or_default ( ) ,
96
+ opts. exclude_ports . clone ( ) . unwrap_or_default ( ) ,
97
97
opts. udp ,
98
98
opts. closed ,
99
99
) ;
@@ -142,63 +142,29 @@ fn main() {
142
142
}
143
143
144
144
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
- }
177
145
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) ;
197
151
}
198
152
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 {
202
168
let vec_str_ports: Vec < String > = ports. iter ( ) . map ( ToString :: to_string) . collect ( ) ;
203
169
204
170
// nmap port style is 80,443. Comma separated with no spaces.
@@ -251,14 +217,6 @@ fn main() {
251
217
}
252
218
}
253
219
}
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( ) ) ;
262
220
}
263
221
264
222
/// Prints the opening title of RustScan
0 commit comments