theHarvester/securitytrailsparser.py
2018-12-27 01:53:12 -06:00

37 lines
1.3 KiB
Python
Executable file

class parser:
def __init__(self, word, text):
self.word = word
self.text = text
self.hostnames = set()
self.ips = set()
def parse_text(self):
subDomain_flag = 0
self.text = str(self.text).splitlines()
# Split lines to get a list of lines.
for index in range(0, len(self.text)):
line = self.text[index].strip()
if '"ip":' in line:
# Extract IP.
ip = ''
for ch in line[7:]:
if ch == '"':
break
else:
ip += ch
self.ips.add(ip)
elif '"subdomains":' in line:
# subdomains start here so set flag to 1.
subDomain_flag = 1
continue
elif subDomain_flag > 0:
if ']' in line:
subDomain_flag = 0
else:
if 'www' in self.word: self.word = str(self.word).replace('www.', '').replace('www', '')
# Remove www from word if entered.
self.hostnames.add(str(line).replace('"', '').replace(',', '') + '.' + self.word)
else:
continue
return list(self.ips), list(self.hostnames)