@@ -69,29 +69,23 @@ pub struct TargetDetails {
6969 * specific network on a network interfaces.
7070 */
7171pub fn compute_network_configuration < ' a > ( interfaces : & ' a [ NetworkInterface ] , scan_options : & ' a Arc < ScanOptions > ) -> ( & ' a NetworkInterface , Vec < & ' a IpNetwork > ) {
72-
73- let interface_name = match & scan_options. interface_name {
74- Some ( name) => String :: from ( name) ,
75- None => {
76-
77- let name = utils:: select_default_interface ( interfaces) . map ( |interface| interface. name ) ;
78-
79- match name {
80- Some ( name) => name,
81- None => {
72+ let selected_interface = match ( & scan_options. interface_name , & scan_options. interface_index ) {
73+ ( Some ( interface_name) , _) => {
74+ find_interface_by_name ( interfaces, interface_name)
75+ } ,
76+ ( None , Some ( interface_index) ) => {
77+ find_interface_by_index ( interfaces, * interface_index)
78+ } ,
79+ _ => {
8280 eprintln ! ( "Could not find a default network interface" ) ;
8381 eprintln ! ( "Use 'arp scan -l' to list available interfaces" ) ;
8482 process:: exit ( 1 ) ;
8583 }
86- }
87- }
8884 } ;
8985
90- let selected_interface: & NetworkInterface = interfaces. iter ( )
91- . find ( |interface| { interface. name == interface_name && interface. is_up ( ) && !interface. is_loopback ( ) } )
92- . unwrap_or_else ( || {
93- eprintln ! ( "Could not find interface with name {}" , interface_name) ;
94- eprintln ! ( "Make sure the interface is up, not loopback and has a valid IPv4" ) ;
86+ let selected_interface = selected_interface. unwrap_or_else ( || {
87+ eprintln ! ( "Could not find the specified interface" ) ;
88+ eprintln ! ( "Make sure the interface is up, not loopback, and has a valid IPv4" ) ;
9589 process:: exit ( 1 ) ;
9690 } ) ;
9791
@@ -103,6 +97,17 @@ pub fn compute_network_configuration<'a>(interfaces: &'a [NetworkInterface], sca
10397 ( selected_interface, ip_networks)
10498}
10599
100+ fn find_interface_by_name < ' a > ( interfaces : & ' a [ NetworkInterface ] , interface_name : & str ) -> Option < & ' a NetworkInterface > {
101+ interfaces. iter ( )
102+ . find ( |interface| interface. name == interface_name && ( cfg ! ( windows) || interface. is_up ( ) ) && !interface. is_loopback ( ) )
103+ }
104+
105+ fn find_interface_by_index < ' a > ( interfaces : & ' a [ NetworkInterface ] , interface_index : u32 ) -> Option < & ' a NetworkInterface > {
106+ interfaces. iter ( )
107+ . find ( |interface| interface. index == interface_index && ( cfg ! ( windows) || interface. is_up ( ) ) && !interface. is_loopback ( ) )
108+ }
109+
110+
106111/**
107112 * Based on the network size and given scan options, this function performs an
108113 * estimation of the scan impact (timing, bandwidth, ...). Keep in mind that
0 commit comments