Repository navigation
Expand file tree
/
Copy pathsub.py
More file actions
68 lines (55 loc) · 2.06 KB
/
Copy pathsub.py
File metadata and controls
68 lines (55 loc) · 2.06 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
import socket
import threading
import time
import logging
# Configure logging
logging.basicConfig(filename='subdomain_finder.log', level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
# Define target domains/IPs
target_domains = ["example.com", "192.168.1.100", "192.168.1.101"]
# You can add more targets here
# Define subdomain wordlist (example)
subdomains = ["www", "mail", "admin", "ftp", "secure", "blog", "shop"]
def check_socket(domain_or_ip, subdomain):
"""
Checks if a socket connection can be established to the given subdomain.
Args:
domain_or_ip (str): The target domain or IP address.
subdomain (str): The subdomain to check.
Returns:
bool: True if connection successful, False otherwise.
"""
try:
# Create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Construct the full domain/IP
host = f"{subdomain}.{domain_or_ip}"
# Attempt to connect
s.connect((host, 80)) # Connect to port 80 (HTTP)
s.close()
logging.info(f"Found subdomain: {host}")
return True
except (socket.gaierror, socket.error) as e:
# Handle connection errors (e.g., DNS resolution, connection refused)
# logging.debug(f"Connection failed for {host}: {e}")
return False
def worker(domain_or_ip, subdomain_list):
"""
Worker thread to check subdomains concurrently.
Args:
domain_or_ip (str): The target domain or IP address.
subdomain_list (list): List of subdomains to check.
"""
for subdomain in subdomain_list:
if check_socket(domain_or_ip, subdomain):
# Handle successful connection (e.g., store in a database, print to console)
pass
if __name__ == "__main__":
threads = []
for target in target_domains:
thread = threading.Thread(target=worker, args=(target, subdomains))
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
print("Subdomain scan complete.")