Skip to content

Commit 09ae5b7

Browse files
authored
Merge pull request #58 from evcsec/ping_sweeper_file_handling
Ping sweeper file handling
2 parents afe4566 + 7d1afbe commit 09ae5b7

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

find_dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def find_dns(target_hosts, output_directory, quiet):
3333
for line in lines:
3434
line = line.strip()
3535
line = line.rstrip()
36-
if ("53/tcp" in line) and ("open" in line):
36+
if ("53/tcp" in line) and ("open" in line) and ("Discovered" not in line):
3737
print(" [=] Found DNS service running on: %s" % (ip_address))
3838
output_file.write("[*] Found DNS service running on: %s\n" % (ip_address))
3939
output_file.write(" [>] %s\n" % (line))

ping_sweeper.py

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

11-
print("[+] Performing ping sweep over %s" % target_hosts)
12-
13-
lines = call_nmap_sweep(target_hosts)
14-
live_hosts = parse_nmap_output_for_live_hosts(lines)
15-
write_live_hosts_list_to_file(output_file, live_hosts)
16-
17-
for ip_address in live_hosts:
18-
print(" [>] Discovered host: %s" % (ip_address))
19-
20-
print("[*] Found %s live hosts" % (len(live_hosts)))
21-
print("[*] Created target list %s" % (output_file))
22-
11+
print("[+] Writing discovered targets to: %s" % output_file)
12+
live_hosts = 0
13+
f = open(output_file, 'w')
2314

24-
def call_nmap_sweep(target_hosts):
25-
SWEEP = "nmap -n -sP %s" % (target_hosts)
15+
print("[+] Performing ping sweep over %s" % target_hosts)
2616

17+
if (os.path.isfile(target_hosts)):
18+
SWEEP = "nmap -n -sP -iL %s" % (target_hosts)
19+
else:
20+
SWEEP = "nmap -n -sP %s" % (target_hosts)
2721
results = subprocess.check_output(SWEEP, shell=True)
28-
lines = str(results, "utf-8").split("\n")
29-
return lines
30-
31-
32-
def parse_nmap_output_for_live_hosts(lines):
33-
def get_ip_from_nmap_line(line):
34-
return line.split()[4]
35-
36-
live_hosts = [get_ip_from_nmap_line(line)
37-
for line in lines
38-
if "Nmap scan report for" in line]
39-
40-
return live_hosts
41-
42-
43-
def write_live_hosts_list_to_file(output_file, live_hosts):
44-
print("[+] Writing discovered targets to: %s" % output_file)
45-
with open(output_file, 'w') as f:
46-
f.write("\n".join(live_hosts))
22+
lines = results.split("\n")
23+
24+
for line in lines:
25+
line = line.strip()
26+
line = line.rstrip()
27+
if ("Nmap scan report for" in line):
28+
ip_address = line.split(" ")[4]
29+
if (live_hosts > 0):
30+
f.write('\n')
31+
f.write("%s" % (ip_address))
32+
print(" [>] Discovered host: %s" % (ip_address))
33+
live_hosts += 1
34+
print("[*] Found %s live hosts" % (live_hosts))
35+
print("[*] Created target list %s" % (output_file))
36+
f.close()

0 commit comments

Comments
 (0)