-
Notifications
You must be signed in to change notification settings - Fork 0
/
subdomain_fetcher.py
55 lines (49 loc) · 2.09 KB
/
subdomain_fetcher.py
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
import os
import json
import requests
def print_welcome_message():
welcome_message = """
_________ ___. .___ .__ _____ __ .__
/ _____/__ _\_ |__ __| _/____ _____ _____ |__| ____ _/ ____\_____/ |_ ____ | |__ ___________
\_____ \| | \ __ \ / __ |/ _ \ / \\__ \ | |/ \ \ __\/ __ \ __\/ ___\| | \_/ __ \_ __ \
/ \ | / \_\ \/ /_/ ( <_> ) Y Y \/ __ \| | | \ | | \ ___/| | \ \___| Y \ ___/| | \/
/_______ /____/|___ /\____ |\____/|__|_| (____ /__|___| / |__| \___ >__| \___ >___| /\___ >__|
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
"""
print(welcome_message)
def get_api_key():
api_key_file = "securitytrails_api_key.txt"
if os.path.exists(api_key_file):
with open(api_key_file, "r") as file:
api_key = file.read().strip()
else:
api_key = input("Enter your SecurityTrails API key: ")
with open(api_key_file, "w") as file:
file.write(api_key)
return api_key
def get_subdomains(api_key, domain):
url = f"https://api.securitytrails.com/v1/domain/{domain}/subdomains?children_only=false&include_inactive=true"
headers = {
"APIKEY": api_key,
"accept": "application/json"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json().get("subdomains", [])
else:
print(f"Failed to fetch subdomains: {response.status_code}")
return []
def save_subdomains_to_file(domain, subdomains):
filename = f"{domain}_subdomains.txt"
with open(filename, "w") as file:
for subdomain in subdomains:
file.write(f"{subdomain}.{domain}\n")
print(f"Subdomains saved to {filename}")
def main():
print_welcome_message()
api_key = get_api_key()
domain = input("Enter the domain name: ")
subdomains = get_subdomains(api_key, domain)
save_subdomains_to_file(domain, subdomains)
if __name__ == "__main__":
main()