Skip to content

Commit 99a9083

Browse files
committed
Split up ping_sweeper method
1 parent e6b9f36 commit 99a9083

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

reconnoitre/ping_sweeper.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ def ping_sweeper(target_hosts, output_directory, quiet):
88
check_directory(output_directory)
99
output_file = output_directory + "/targets.txt"
1010

11-
print("[+] Writing discovered targets to: %s" % output_file)
12-
f = open(output_file, 'w')
13-
1411
print("[+] Performing ping sweep over %s" % target_hosts)
1512

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)
2014
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+
2217
for ip_address in live_hosts:
2318
print(" [>] Discovered host: %s" % (ip_address))
19+
2420
print("[*] Found %s live hosts" % (len(live_hosts)))
2521
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
2729

2830

2931
def parse_nmap_output_for_live_hosts(lines):
@@ -36,3 +38,9 @@ def get_ip_from_nmap_line(line):
3638

3739
return live_hosts
3840

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

Comments
 (0)