-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubdomain_enum.py
More file actions
61 lines (48 loc) · 1.82 KB
/
Copy pathsubdomain_enum.py
File metadata and controls
61 lines (48 loc) · 1.82 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
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')
import requests
import argparse
from urllib.parse import urlparse
requests.packages.urllib3.disable_warnings()
def enumerate_subdomains(domain):
"""
Finds valid subdomains for a given domain from a predefined list.
"""
print(f"[*] Starting subdomain enumeration for: {domain}")
found_subdomains = []
# A small list of common subdomains. This could be read from a large file.
subdomain_list = [
"www", "mail", "ftp", "localhost", "webmail", "smtp", "pop", "ns1", "ns2",
"admin", "test", "dev", "blog", "shop", "api", "vpn", "m", "portal", "cpanel"
]
for sub in subdomain_list:
sub_url = f"http://{sub}.{domain}"
try:
requests.get(sub_url, timeout=3, allow_redirects=False)
print(f"[+] Found: {sub_url}")
found_subdomains.append(sub_url)
except requests.ConnectionError:
pass
except Exception as e:
print(f"[-] An error occurred trying {sub_url}: {e}")
return found_subdomains
def main():
parser = argparse.ArgumentParser(description="Enumerate subdomains for a given URL.")
parser.add_argument("url", help="The target URL or domain (e.g., https://example.com or example.com)")
args = parser.parse_args()
raw_input = args.url
if '://' not in raw_input:
raw_input = '//' + raw_input
domain = urlparse(raw_input).netloc
if not domain:
print(f"Error: Could not parse a valid domain from '{args.url}'")
return
# Handle URLs with ports e.g. localhost:8000
if ':' in domain:
domain = domain.split(':')[0]
found = enumerate_subdomains(domain)
if not found:
print("\n[-] No common subdomains found.")
if __name__ == "__main__":
main()