czds/czds

62 lines
1.8 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
# Function to authenticate and get access token
authenticate() {
username="$1"
password="$2"
# Make an authentication request and inline the URL
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\"}")
# Extract and return the access token
echo "$response" | grep -o '"accessToken":"[^"]*' | cut -d '"' -f 4
2023-11-02 23:12:13 -07:00
}
# Function to download a zone file
download_zone() {
url="$1"
token="$2"
2024-02-15 12:34:44 -08:00
tld=$(basename "$url" .zone)
# Make the GET request and save the response to a file
2024-02-15 12:34:44 -08:00
echo "Downloading $url..."
curl --progress-bar -o zonefiles/$tld.txt.gz -H "Authorization: Bearer $token" "$url"
echo "Downloaded zone file to zonefiles/$tld.txt.gz"
2023-11-02 23:12:13 -07:00
}
# Main program starts here
echo "ICANN Zone Data Service Script"
# Get username and password
username=${CZDS_USER:-$(read -p "ICANN Username: " user && echo "$user")}
password=${CZDS_PASS:-$(read -sp "ICANN Password: " pass && echo "$pass" && echo)}
# Authenticate and get token
echo "Authenticating..."
token=$(authenticate "$username" "$password")
# Check if authentication was successful
if [ -z "$token" ]; then
echo "Authentication failed."
exit 1
2023-11-02 23:12:13 -07:00
fi
echo "Fetching zone file links..."
# Fetch zone links with inline URL and download zone files
zone_links=$(curl -s -H "Authorization: Bearer $token" "https://czds-api.icann.org/czds/downloads/links" | grep -o 'https://[^"]*')
2024-02-15 12:34:44 -08:00
# Create output directory if it does not exist
mkdir -p zonefiles
2023-11-02 23:12:13 -07:00
# Download zone files
for url in $zone_links; do
2024-02-15 12:34:44 -08:00
download_zone "$url" "$token"
2023-11-02 23:12:13 -07:00
done
echo "All zone files downloaded."