-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy path1-mix-ping_sweep.py
57 lines (50 loc) · 1.65 KB
/
1-mix-ping_sweep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
##########################################################################
## [Name]: 1-mix-ping_sweep.py -- a recon/enumeration script
## [Author]: Re4son re4son [at] whitedome.com.au
##------------------------------------------------------------------------
## [Details]:
## Script to perform a ping sweep over a given range and list each live
## host in file <outputdir>/targets.txt.
##------------------------------------------------------------------------
## [Usage]:
## python 1-mix-ping_sweep.py <target IP range> <output directory>
##########################################################################
import subprocess
import sys
import os
if len(sys.argv) != 3:
print "\nUsage: 1-mix-ping-sweep.py <range> <output directory>\n"
sys.exit(0)
RANGE = sys.argv[1].strip()
OUTDIR = sys.argv[2].strip()
try:
os.stat(OUTDIR)
except:
os.mkdir(OUTDIR)
print " "
print "[!] %s didn't exist, created %s" % (OUTDIR, OUTDIR)
outfile = OUTDIR + "/targets.txt"
res = 0
f = open(outfile, 'w')
print " "
print "[+] Performing ping sweep over %s" % (RANGE)
SWEEP = "nmap -n -sP %s" % (RANGE)
results = subprocess.check_output(SWEEP, shell=True)
lines = results.split("\n")
for line in lines:
line = line.strip()
line = line.rstrip()
if ("Nmap scan report for" in line):
ip_address = line.split(" ")[4]
if (res > 0):
f.write('\n')
f.write("%s" % (ip_address))
print "[*] %s" % (ip_address)
res += 1
print " "
print "[*] Found %s live hosts" % (res)
print "[*] Created target list %s" % (outfile)
print "[*] Paste %s into 3-mix-recon.py" % (outfile)
print " "
f.close()