@@ -275,8 +275,7 @@ def settings(single=None):
275275 # targets.
276276 exploit (query )
277277
278-
279- def targets (clobber = True ):
278+ def targets (clobber = True , hostLimit = - 1 ):
280279 """Function to gather target host(s) from Shodan."""
281280 global query
282281 global stop_animation
@@ -318,10 +317,14 @@ def targets(clobber=True):
318317 for _ in xrange (toolbar_width ):
319318 time .sleep (0.1 )
320319 for service in result ['matches' ]:
321- log .write ("{}{}" .format (service ['ip_str' ], os .linesep ))
320+ if hostLimit > 0 or hostLimit < 0 :
321+ log .write ("{}{}" .format (service ['ip_str' ], os .linesep ))
322+ hostLimit -= 1
323+ else :
324+ break
325+ hostpath = os .path .abspath ("hosts.txt" )
326+ stop_animation = True
322327
323- hostpath = os .path .abspath ("hosts.txt" )
324- stop_animation = True
325328
326329 print ("\n \n \n [{}]Done." .format (t .green ("+" )))
327330 print ("[{}]Host list saved to {}" .format (t .green ("+" ), hostpath ))
@@ -490,17 +493,21 @@ def try_shodan():
490493
491494 if action == '1' :
492495 usage ()
496+
493497 elif action == '2' :
498+ hostLimit = - 1
499+ limitYN = raw_input ("\n [" + t .magenta ("?" ) + "]Limit number of hosts? [y/n]: " ).lower ()
500+ if limitYN == 'y' :
501+ hostLimit = input ("\n [" + t .magenta ("?" ) + "]How many?: " )
494502 if not os .path .isfile ("hosts.txt" ):
495- targets (True )
503+ targets (True , hostLimit )
496504 else :
497505 append = raw_input (
498506 "\n [" + t .magenta ("?" ) + "]Append hosts to file or overwrite? [A/O]: " ).lower ()
499-
500507 if append == 'a' :
501- targets (False )
508+ targets (False , hostLimit )
502509 elif append == 'o' :
503- targets (True )
510+ targets (True , hostLimit )
504511 else :
505512 print ("\n [{}]Unhandled Option." .format (t .red ("!" )))
506513 elif action == '3' :
0 commit comments