@@ -8,22 +8,24 @@ def ping_sweeper(target_hosts, output_directory, quiet):
8
8
check_directory (output_directory )
9
9
output_file = output_directory + "/targets.txt"
10
10
11
- print ("[+] Writing discovered targets to: %s" % output_file )
12
- f = open (output_file , 'w' )
13
-
14
11
print ("[+] Performing ping sweep over %s" % target_hosts )
15
12
16
- SWEEP = "nmap -n -sP %s" % (target_hosts )
17
- results = subprocess .check_output (SWEEP , shell = True )
18
- lines = str (results , "utf-8" ).split ("\n " )
19
-
13
+ lines = call_nmap_sweep (target_hosts )
20
14
live_hosts = parse_nmap_output_for_live_hosts (lines )
21
- f .write ("\n " .join (live_hosts ))
15
+ write_live_hosts_list_to_file (output_file , live_hosts )
16
+
22
17
for ip_address in live_hosts :
23
18
print (" [>] Discovered host: %s" % (ip_address ))
19
+
24
20
print ("[*] Found %s live hosts" % (len (live_hosts )))
25
21
print ("[*] Created target list %s" % (output_file ))
26
- f .close ()
22
+
23
+
24
+ def call_nmap_sweep (target_hosts ):
25
+ SWEEP = "nmap -n -sP %s" % (target_hosts )
26
+ results = subprocess .check_output (SWEEP , shell = True )
27
+ lines = str (results , "utf-8" ).split ("\n " )
28
+ return lines
27
29
28
30
29
31
def parse_nmap_output_for_live_hosts (lines ):
@@ -36,3 +38,9 @@ def get_ip_from_nmap_line(line):
36
38
37
39
return live_hosts
38
40
41
+
42
+ def write_live_hosts_list_to_file (output_file , live_hosts ):
43
+ print ("[+] Writing discovered targets to: %s" % output_file )
44
+ with open (output_file , 'w' ) as f :
45
+ f .write ("\n " .join (live_hosts ))
46
+
0 commit comments