-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscan.py
executable file
·67 lines (62 loc) · 2.28 KB
/
subscan.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
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
#
#subscan.py
#Developer: Cody Skinner
#ver 0.1.1
import subprocess
import sys
import getopt
import re
def main(argv):
inputfile = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv, 'hi:o:',['ifile=','ofile='])
except getopt.GetoptError:
print ('usage: subscan.py -i <inputfile> -o <outputfile>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('subscan.py')
print('Tool for checking host information for a list of domains')
print('Includes option to extract NXDOMAIN results to a text file')
print('usage: subscan.py -i <inputfile> -o <outputfile>')
sys.exit()
elif opt in ('-i', '--ifile'):
inputfile = arg
elif opt in ('-o', '--ofile'):
outputfile = arg
if not inputfile or not outputfile:
print('usage: subscan.py -i <inputfile> -o <outputfile>')
sys.exit()
print('Checking host information for domains in list')
print('Please be patient, this may take a while with long lists')
with open(inputfile, 'r') as i:
line = i.readline().rstrip()
with open(outputfile, 'a') as out:
while line:
out.write('\n***' + line + '***\n')
cmd = ['host', line]
with subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True) as proc:
result = proc.stdout.read()
out.write(str(result) + '\n')
line = i.readline().rstrip()
print('Output saved to ', outputfile)
cont = input('Extract NXDOMAIN listings? (y/N): ')
if cont == 'y' or cont == 'Y':
nxdomain = 'nxdomain-' + outputfile
pattern = re.compile("NXDOMAIN")
strippat = re.compile(r'^(?:\S+\s){1}(\S+)')
with open(outputfile, 'r') as results:
nxdline = results.readline()
with open(nxdomain, 'a') as o:
while nxdline:
if pattern.search(nxdline) != None:
host = strippat.search(nxdline).group(1)
o.write(host + '\n')
nxdline = results.readline()
print('NXDOMAIN list saved to: ', nxdomain)
else:
sys.exit()
if __name__ == "__main__":
main(sys.argv[1:])