Hello!
Coming at you today with a script that you can use that leverages Censys Python to grab all of your domains/subdomains from your ASM platform into a cvs file. Huge s/o to
import requests
import json
import csv
url = "https://app.censys.io/api/v1/assets/subdomains"
headers = {
"accept": "application/json",
"Censys-Api-Key": "<API KEY HERE>"
}
# Initialize an empty list to store all the results
all_results = ]
page_number = 1
total_pages = 1000 # You can update this based on the total number of pages you have
while page_number <= total_pages:
params = {"pageNumber": page_number, "pageSize": 500}
response = requests.get(url, headers=headers, params=params)
data = response.json()
# Check if the response contains the expected key for subdomain data
if "subdomains" in data:
all_results.extend(dataa"subdomains"])
else:
print("Error: Subdomain data not found in response.")
print("Response JSON:", data)
break
page_number += 1
# Define the field names for the CSV file
field_names = "domain", "subdomain", "tags"]
# Write all the results to a CSV file
with open("subdomains_export.csv", "w", newline="", encoding="utf-8") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=field_names)
writer.writeheader()
for result in all_results:
writer.writerow(result)
print("CSV file generated successfully.")