import requests
import sys

# the domain to scan for subdomains
domain = "email.com" 

# read all subdomains
file = open("subdomains.txt")

# read all content
content = file.read()

# split by new lines
subdomains = content.splitlines()

# a list of discovered subdomains
discovered_subdomains = []
for subdomain in subdomains:
    # construct the url
    url = f"http://{subdomain}.{domain}"
    try:
        # if this raises an ERROR, that means the subdomain does not exist
        requests.get(url)
    except requests.ConnectionError:
        # if the subdomain does not exist, just pass, print nothing
        pass
    except KeyboardInterrupt:
        # if the user does ctrl+c
        print("Hello user, you have pressed ctrl+c, so terminating!")
        sys.exit()
    else:
        print("[+] Discovered subdomain:", url)
        # append the discovered subdomain to our list
        discovered_subdomains.append(url)
# save the discovered subdomains into a file
with open("discovered_subdomains.txt", "w") as f:
    for subdomain in discovered_subdomains:
        print(subdomain, file=f)
