@@ -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,21 +120,32 @@ 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
-
124
- print "@ Searching for the network gateway address ..."
125
123
124
+ print "@ Searching for the network gateway address ..."
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
- # 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
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
138
149
139
150
if self .gateway is not None and self .network is not None :
140
151
print "@ Gateway is %s on network %s ." % ( self .gateway , self .network )
@@ -150,12 +161,13 @@ def __init__( self, interface, gateway = None, network = None, kill = False, all
150
161
self .targets = self .endpoints
151
162
else :
152
163
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 ) )
158
164
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 ) )
159
171
choice = choice .strip ()
160
172
if choice == '*' :
161
173
self .targets = self .endpoints
@@ -164,6 +176,8 @@ def __init__( self, interface, gateway = None, network = None, kill = False, all
164
176
self .find_alive_hosts ()
165
177
else :
166
178
self .targets .append ( self .endpoints [ int (choice ) ] )
179
+ except KeyboardInterrupt :
180
+ quit ()
167
181
except Exception as e :
168
182
print "@ Invalid choice!"
169
183
choice = None
0 commit comments