-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubdomain_enumeration.py
More file actions
79 lines (64 loc) · 2.29 KB
/
subdomain_enumeration.py
File metadata and controls
79 lines (64 loc) · 2.29 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
import requests
import threading
import time
MAX_THREADS = 100
timeout = 5
def checkSubDomain(domain, subdomain, found_subdomains):
https_url = f"https://{subdomain}.{domain}"
try:
response = requests.get(https_url, timeout=timeout)
if response.status_code == 200:
found_subdomains.append(f"{subdomain}.{domain}")
print(f"{subdomain}.{domain}")
return f"{subdomain}.{domain}"
except requests.exceptions.Timeout:
pass
except requests.exceptions.RequestException:
http_url = f"http://{subdomain}.{domain}"
try:
response = requests.get(http_url, timeout=timeout)
if response.status_code == 200:
found_subdomains.append(http_url)
print(f"{http_url}")
return http_url
except requests.exceptions.Timeout:
pass
except requests.exceptions.RequestException:
pass
return None
def load_subdomains(filename="wordlist/Subdomain.txt"):
try:
with open(filename, "r") as file:
return [line.strip() for line in file.readlines()]
except FileNotFoundError:
print(f"{filename} not found.")
return []
def worker(domain, subdomain, found_subdomains):
checkSubDomain(domain, subdomain, found_subdomains)
def thread_subdomain_check(domain, subdomains):
found_subdomains = []
threads = []
print("Subdomain found")
for sub in subdomains:
while len(threads) >= MAX_THREADS:
for thread in threads:
thread.join()
threads.clear()
thread = threading.Thread(target=worker, args=(domain, sub, found_subdomains))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
return found_subdomains
def run_subdomain_enumeration():
domain = input("Enter domain name (e.g. google.com): ") or 'google.com'
subdomains = load_subdomains()
if not subdomains:
print("No subdomains found.")
else:
start_time = time.time()
found_subdomains = thread_subdomain_check(domain, subdomains)
elapsed_time = time.time() - start_time
print(f"Scan completed in {elapsed_time:.2f} seconds.")
if __name__ == '__main__':
run_subdomain_enumeration()