czds/czds

67 lines
2.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2023-11-02 23:12:13 -07:00
# ICANN API for the Centralized Zones Data Service - developed by acidvegas (https://git.acid.vegas/czds)
# Reference: https://czds.icann.org
2023-11-02 23:12:13 -07:00
# Main program starts here
echo "ICANN Zone Data Service Script"
# Define the current date for data organization
now=$(date +"%Y-%m-%d")
# Define the output directory
output="zonefiles/$now"
# Get username and password (interactive if not set by environment variables)
username=${CZDS_USER:-$(read -p "ICANN Username: " user && echo "$user")}
password=${CZDS_PASS:-$(read -sp "ICANN Password: " pass && echo "$pass")}
2023-11-02 23:12:13 -07:00
echo "Authenticating as $username..."
2023-11-02 23:12:13 -07:00
# Make an authentication request
response=$(curl -s -X POST "https://account-api.icann.org/api/authenticate" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "{\"username\":\"$username\",\"password\":\"$password\"}")
2023-11-02 23:12:13 -07:00
# Extract and return the access access_token
access_token=$(echo "$response" | grep -o '"accessToken":"[^"]*' | cut -d '"' -f 4)
2023-11-02 23:12:13 -07:00
# Check if authentication was successful
[ -z $access_token ] && echo "error: authentication failed" && exit 1
echo "Authenticated successfully & recieved access_token $access_token"
# Create output directory
mkdir -p $output
echo "Fetching zone report..."
# Get your zone report stats from the API
curl --progress-bar -o $output/.stats.csv -H "Authorization: Bearer $access_token" https://czds-api.icann.org/czds/requests/report
echo "Scrubbing report for privacy..."
# Redact username from report for privacy
sed -i 's/$username/nobody@no.name/g' $output/report.csv
2023-11-02 23:12:13 -07:00
echo "Fetching zone file links..."
# Get the zone file links from the API
zone_links=$(curl -s -H "Authorization: Bearer $access_token" https://czds-api.icann.org/czds/downloads/links | grep -o 'https://[^"]*')
2024-02-15 12:34:44 -08:00
2023-11-02 23:12:13 -07:00
# Download zone files
for url in $zone_links; do
tld=$(basename "$url" .zone)
echo "Downloading $url..."
# Make the GET request and save the response to a file
curl --progress-bar -o $output/$tld.txt.gz -H "Authorization: Bearer $access_token" "$url"
echo "Downloaded $tld zone file to zonefiles/$tld.txt.gz (extracting...)"
# Unzip the zone file
gunzip $output/$tld.txt.gz
2023-11-02 23:12:13 -07:00
done
echo "All zone files downloaded."