-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsubdomain.py
43 lines (38 loc) · 1.53 KB
/
subdomain.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
import requests
def getSubdomains(domain):
print('# Subdomain scanner')
domainLower = domain.lower()
if domainLower.startswith('www.'):
domainLower = domainLower.replace('www.', '')
# Get subdomains from CRT.SH site.
req = requests.get('https://crt.sh/?q={}'.format(domainLower)).text.splitlines()
subdomains = []
for line in req:
if '<BR>' in line:
subdomain = line.replace('<TD>', '').replace('<BR>', ' ').replace('</TD>', '').split()
try:
for i in range(0, 5):
if subdomain[i] not in subdomains:
if '*.' in subdomain[i]:
pass
else:
if domainLower in subdomain[i]:
subdomains.append(subdomain[i])
except:
pass
# Get subdomains from hackertarget.com
req = requests.get('https://api.hackertarget.com/hostsearch/?q={}'.format(domainLower)).text.splitlines()
for subdomain in req:
subdomain = subdomain.replace(',' , ' ').split()
if subdomain[0] in subdomains:
pass
else:
subdomains.append(subdomain[0])
if len(subdomains) > 1:
print('- {} Subdomains found, Results have been saved'.format(len(subdomains)))
saveOutput = open('{}_Subdomains.txt'.format(domain), 'a')
for domain in subdomains:
saveOutput.write(domain+'\n')
saveOutput.close()
else:
print('- No subdomains found')