@@ -87,9 +87,9 @@ def find_alive_hosts( self ):
87
87
88
88
# broadcast arping ftw
89
89
ans ,unans = srp ( Ether ( dst = "ff:ff:ff:ff:ff:ff" ) / ARP ( pdst = self .network ),
90
- verbose = False ,
91
- filter = "arp and arp[7] = 2" ,
92
- timeout = 2 ,
90
+ verbose = False ,
91
+ filter = "arp and arp[7] = 2" ,
92
+ timeout = 2 ,
93
93
iface_hint = self .network )
94
94
95
95
for snd ,rcv in ans :
@@ -120,32 +120,21 @@ def __init__( self, interface, gateway = None, network = None, kill = False, all
120
120
raise Exception ( "Only root can run this script." )
121
121
122
122
self .__preload_mac_table ()
123
-
123
+
124
124
print "@ Searching for the network gateway address ..."
125
-
125
+
126
126
# for route in conf.route.routes:
127
127
for net , msk , gw , iface , addr in conf .route .routes :
128
128
# found a route for given interface
129
129
if iface == self .interface :
130
130
network = ltoa ( net )
131
-
132
- # Mac OS X
133
- if sys .platform == 'darwin' :
134
- if self .gateway is None :
135
- if gw != '0.0.0.0' :
136
- self .gateway = gw
137
- elif self .network is None and network != '0.0.0.0' :
138
- bits = self .__bit_count ( msk )
139
- self .network = "%s/%d" % ( network , bits )
140
- # Linux
141
- else :
142
- # compute network representation if not yet done
143
- if network .split ('.' )[0 ] == addr .split ('.' )[0 ]:
144
- bits = self .__bit_count ( msk )
145
- self .network = "%s/%d" % ( network , bits )
146
- # search for a valid network gateway
147
- if self .gateway is None and gw != '0.0.0.0' :
148
- self .gateway = gw
131
+ # compute network representation if not yet done
132
+ if network .split ('.' )[0 ] == addr .split ('.' )[0 ]:
133
+ bits = self .__bit_count ( msk )
134
+ self .network = "%s/%d" % ( network , bits )
135
+ # search for a valid network gateway
136
+ if self .gateway is None and gw != '0.0.0.0' :
137
+ self .gateway = gw
149
138
150
139
if self .gateway is not None and self .network is not None :
151
140
print "@ Gateway is %s on network %s ." % ( self .gateway , self .network )
@@ -161,13 +150,12 @@ def __init__( self, interface, gateway = None, network = None, kill = False, all
161
150
self .targets = self .endpoints
162
151
else :
163
152
while choice is None :
153
+ for i , item in enumerate ( self .endpoints ):
154
+ ( mac , ip ) = item
155
+ vendor = self .__find_mac_vendor ( mac )
156
+ print " [%d] %s %s %s" % ( i , mac , ip , "( %s )" % vendor if vendor else '' )
157
+ choice = raw_input ( "@ Choose [0-%d] (* to select all, r to refresh): " % (len (self .endpoints ) - 1 ) )
164
158
try :
165
- for i , item in enumerate ( self .endpoints ):
166
- ( mac , ip ) = item
167
- vendor = self .__find_mac_vendor ( mac )
168
- print " [%d] %s %s %s" % ( i , mac , ip , "( %s )" % vendor if vendor else '' )
169
-
170
- choice = raw_input ( "@ Choose [0-%d] (* to select all, r to refresh): " % (len (self .endpoints ) - 1 ) )
171
159
choice = choice .strip ()
172
160
if choice == '*' :
173
161
self .targets = self .endpoints
@@ -176,8 +164,6 @@ def __init__( self, interface, gateway = None, network = None, kill = False, all
176
164
self .find_alive_hosts ()
177
165
else :
178
166
self .targets .append ( self .endpoints [ int (choice ) ] )
179
- except KeyboardInterrupt :
180
- quit ()
181
167
except Exception as e :
182
168
print "@ Invalid choice!"
183
169
choice = None
0 commit comments