@@ -9,7 +9,6 @@ def ping_sweeper(target_hosts, output_directory, quiet):
9
9
output_file = output_directory + "/targets.txt"
10
10
11
11
print ("[+] Writing discovered targets to: %s" % output_file )
12
- live_hosts = 0
13
12
f = open (output_file , 'w' )
14
13
15
14
print ("[+] Performing ping sweep over %s" % target_hosts )
@@ -18,16 +17,22 @@ def ping_sweeper(target_hosts, output_directory, quiet):
18
17
results = subprocess .check_output (SWEEP , shell = True )
19
18
lines = str (results , "utf-8" ).split ("\n " )
20
19
21
- for line in lines :
22
- line = line .strip ()
23
- line = line .rstrip ()
24
- if ("Nmap scan report for" in line ):
25
- ip_address = line .split (" " )[4 ]
26
- if (live_hosts > 0 ):
27
- f .write ('\n ' )
28
- f .write ("%s" % (ip_address ))
29
- print (" [>] Discovered host: %s" % (ip_address ))
30
- live_hosts += 1
31
- print ("[*] Found %s live hosts" % (live_hosts ))
20
+ live_hosts = parse_nmap_output_for_live_hosts (lines )
21
+ f .write ("\n " .join (live_hosts ))
22
+ for ip_address in live_hosts :
23
+ print (" [>] Discovered host: %s" % (ip_address ))
24
+ print ("[*] Found %s live hosts" % (len (live_hosts )))
32
25
print ("[*] Created target list %s" % (output_file ))
33
26
f .close ()
27
+
28
+
29
+ def parse_nmap_output_for_live_hosts (lines ):
30
+ def get_ip_from_nmap_line (line ):
31
+ return line .split ()[4 ]
32
+
33
+ live_hosts = [get_ip_from_nmap_line (line )
34
+ for line in lines
35
+ if "Nmap scan report for" in line ]
36
+
37
+ return live_hosts
38
+
0 commit comments