-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectory_listing.py
More file actions
78 lines (64 loc) · 2.25 KB
/
directory_listing.py
File metadata and controls
78 lines (64 loc) · 2.25 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
import requests
import threading
import time
MAX_THREADS = 100
timeout = 5
def checkDirectory(domain, directory, found_directories):
url = f"https://{domain}/{directory}"
try:
response = requests.get(url, timeout=timeout)
if response.status_code == 200:
found_directories.append(url)
print(f"{url}")
return url
except requests.exceptions.Timeout:
pass
except requests.exceptions.RequestException:
http_url = f"http://{domain}/{directory}"
try:
response = requests.get(http_url, timeout=timeout)
if response.status_code == 200:
found_directories.append(http_url)
print(f"Found: {http_url}")
return http_url
except requests.exceptions.Timeout:
pass
except requests.exceptions.RequestException:
pass
return None
def load_directories(filename="wordlist/directory.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, directory, found_directories):
checkDirectory(domain, directory, found_directories)
def thread_directory_check(domain, directories):
found_directories = []
threads = []
print("Directories found:")
for directory in directories:
while len(threads) >= MAX_THREADS:
for thread in threads:
thread.join()
threads.clear()
thread = threading.Thread(target=worker, args=(domain, directory, found_directories))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
return found_directories
def run_directory_listing():
domain = input("Enter domain name (e.g. google.com): ") or 'google.com'
directories = load_directories()
if not directories:
print("No directories found.")
else:
start_time = time.time()
found_directories = thread_directory_check(domain, directories)
elapsed_time = time.time() - start_time
print(f"Scan completed in {elapsed_time:.2f} seconds.")
if __name__ == '__main__':
run_directory_listing()